<ol>
<li><p><strong>Escape single lines as strings:</strong></p>

<pre><code>{{ '{% set foo = "bar" %}' }}
</code></pre></li>
<li><p><strong>Use <a href="http://twig.sensiolabs.org/doc/tags/autoescape.html" rel="nofollow"><code>autoescape</code></a> to escape multiple lines, optionally specifying a syntax (see docs):</strong></p>

<pre><code>{% autoescape %}
     {% if foo != "bar" %}
         {% set foo = "bar" %}
     {% endif %}
{% endautoescape %}
</code></pre></li>
<li><p><strong>Use <a href="http://twig.sensiolabs.org/doc/tags/verbatim.html" rel="nofollow"><code>verbatim</code></a> to treat multiple lines as raw text</strong>:</p>

<pre><code>{% verbatim %}
     {% if foo != "bar" %}
         {% set foo = "bar" %}
     {% endif %}   
{% endverbatim %}
</code></pre></li>
</ol>

CC BY-SA 3.0
2017-01-24T17:23:17.243Z
might want to also add the |raw filter here for completeness as the question does say "prevent it from being processed"?
billythekid
CC BY-SA 3.0
2014-06-15T13:19:24.053Z
2014-06-26T21:36:56.647Z
2014-06-26T21:36:56.647Z
nicael
<p>How do I escape Twig code to prevent it from being processed?</p>

<templating><escaping>
How can I escape Twig code to prevent it from being parsed?
# How can I escape Twig code to prevent it from being parsed?

(Asked by: username_0 on 2014-06-15)

How do I escape Twig code to prevent it from being processed?

**Tags:** templating, escaping

---

## 1 answers

### Answer by username_0 on 2014-06-15. Score: 12 | Accepted answer

Escape single lines as strings:
{{ '{% set foo = "bar" %}' }}

Use autoescape to escape multiple lines, optionally specifying a syntax (see docs):
{% autoescape %}
     {% if foo != "bar" %}
         {% set foo = "bar" %}
     {% endif %}
{% endautoescape %}

Use verbatim to treat multiple lines as raw text:
{% verbatim %}
     {% if foo != "bar" %}
         {% set foo = "bar" %}
     {% endif %}   
{% endverbatim %}

> **Comments:**
> **username_1**: might want to also add the |raw filter here for completeness as the question does say "prevent it from being processed"?  

---

