How to escape Nunjucks curly braces for use in code examples
Say you want to demonstrate a Nunjucks code snippet on your site without actually rendering that code in your template:
// An example filter
{{ data | myFilter }}
There are two ways to achieve this:
-
Wrap your code in a
{% raw %}
block:{% raw %}
{{ data | myFilter }}
{% endraw %}{% verbatim %}{% endverbatim %}
works as well. -
But there’s a simpler way for shorter code pieces:
{{ '{{ variable }}' }}
Sources: