Answers.Body: <p>The difference between "raw" and "escape" is sometimes confusing... Try this instead:</p>
  
  <pre><code>{{ element.blockContent|e }}
  </code></pre>
  
  <p><br/>
  <strong><a href="http://twig.sensiolabs.org/doc/filters/escape.html">escape:</a></strong></p>
  
  <blockquote>
    <p>The escape filter escapes a string for safe insertion into the final output.</p>
  </blockquote>
  
  <p><br/>
  <strong><a href="http://twig.sensiolabs.org/doc/filters/raw.html">raw:</a></strong></p>
  
  <blockquote>
    <p>The raw filter marks the value as being "safe", which means that in an environment with automatic escaping enabled this variable will not be escaped if raw is the last filter applied to it.</p>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-05T17:46:45.283Z
Answers.Text: Thanks for this. It turned out the problem for me was actually something else (see below), but this is still useful to know.
Answers.UserDisplayName: Nick F
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-05T17:31:59.080Z
Answers.LastActivityDate: 2014-08-05T17:31:59.080Z
Answers.UserDisplayName: Lindsey D
Answers.Body: <p>For what it's worth, the problem was due to a mistake on my part: the field in question had been set up as Rich Text, and then switched to Plain Text. I guess the original HTML had been encoded going into the database when the field was still Rich Text, and so was already entity-encoded before it even reached the template. When I pasted the HTML in question back in and saved the post again all was well.</p>
  
  <p>So for me, the solution was: make sure that the HTML was definitely saved as raw HTML in a Plain Text field.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-05T17:46:05.077Z
Answers.LastActivityDate: 2014-08-05T19:10:38.513Z
Answers.LastEditDate: 2014-08-05T19:10:38.513Z
Answers.UserDisplayName: Nick F
Body: <p>I have a field in a matrix block that is used for video embed codes. I want to output the contents of that field directly as HTML. However, it always seems to get entity-encoded (ie. the <code>&lt;</code> and <code>&gt;</code> get converted to <code>&amp;lt;</code> and <code>&amp;gt;</code>), so the html just appears as text.</p>
  
  <p>I know about Twig's <a href="http://twig.sensiolabs.org/doc/filters/raw.html" rel="noreferrer">|raw filter</a>, so I tried outputting the field's content through it (eg. using <code>{{ element.blockContent|raw }}</code>), but it seems to make no difference. Can anyone tell me what I'm doing wrong?</p>
  
  <p>(Just in case it's relevant, this is a sub-template that is being included in a <code>for</code> loop that goes through the matrix blocks and outputs them)</p>
  
Tags: <templating><filter><escaping>
Title: How to output a field as raw HTML?
ThreadText: # How to output a field as raw HTML?
  
  (Asked by: username_0 on 2014-08-05)
  
  I have a field in a matrix block that is used for video embed codes. I want to output the contents of that field directly as HTML. However, it always seems to get entity-encoded (ie. the `<` and `>` get converted to `&lt;` and `&gt;`), so the html just appears as text.
  
  I know about Twig's [|raw filter](http://twig.sensiolabs.org/doc/filters/raw.html), so I tried outputting the field's content through it (eg. using `{{ element.blockContent|raw }}`), but it seems to make no difference. Can anyone tell me what I'm doing wrong?
  
  (Just in case it's relevant, this is a sub-template that is being included in a `for` loop that goes through the matrix blocks and outputs them)
  
  **Tags:** templating, filter, escaping
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2014-08-05. Score: 8 | Accepted answer
  
  For what it's worth, the problem was due to a mistake on my part: the field in question had been set up as Rich Text, and then switched to Plain Text. I guess the original HTML had been encoded going into the database when the field was still Rich Text, and so was already entity-encoded before it even reached the template. When I pasted the HTML in question back in and saved the post again all was well.
  
  So for me, the solution was: make sure that the HTML was definitely saved as raw HTML in a Plain Text field.
  
  
  ---
  
  ### Answer by username_1 on 2014-08-05. Score: 12
  
  The difference between "raw" and "escape" is sometimes confusing... Try this instead:
  
  ```
  {{ element.blockContent|e }}
  
  ```
  
  **[escape:](http://twig.sensiolabs.org/doc/filters/escape.html)**
  
  > The escape filter escapes a string for safe insertion into the final output.
  
  **[raw:](http://twig.sensiolabs.org/doc/filters/raw.html)**
  
  > The raw filter marks the value as being "safe", which means that in an environment with automatic escaping enabled this variable will not be escaped if raw is the last filter applied to it.
  
  > **Comments:**
  > **username_0**: Thanks for this. It turned out the problem for me was actually something else (see below), but this is still useful to know.  
  
  ---
  
  