How to escape Twig delimiters in a Twig template?

The easiest way is to output the variable delimiter ({{) by using a variable expression:

{{ '{{' }}

Alternatives (used when you have to escape too much) are raw (verbatim since 1.12) blocks:

{% raw %}
    <ul>
    {% for item in seq %}
        <li>{{ item }}</li>
    {% endfor %}
    </ul>
{% endraw %}

Actually, it’s quite well documented.

Leave a Comment