3

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

12
  1. Escape single lines as strings:

    {{ '{% set foo = "bar" %}' }}
    
  2. Use autoescape to escape multiple lines, optionally specifying a syntax (see docs):

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

    {% verbatim %}
         {% if foo != "bar" %}
             {% set foo = "bar" %}
         {% endif %}   
    {% endverbatim %}
    
  • might want to also add the |raw filter here for completeness as the question does say "prevent it from being processed"? – billythekid Jan 24 '17 at 17:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.