Escaping curly braces in Jinja2 is possible, but it looks awful:
{{ "{" }}
{{ "{{" }}
{{ "}" }}
{{ "}}" }}
{{ {{ url_for('home') }} }}
{% raw %}
<p>Go <a href="{{ url_for('home') }}">Home</a></p>
{% endraw %}
What about supporting something else, since this is a common task? Some possibilities:
\{ and \{\{Pro: simple, intuitive.
Con: what if you really want a backslash, like if you're templating Windows paths?
鈽儃 and 鈽儃鈽儃Unicode snowmen look kinda like curly braces.
Pro: Avoids the con of option 1, since using this combination is rare.
Con: Hard to type, and kind of weird.
_{_ and _{{_Pro: Don't have to escape every single one, making it more readable.
Con: What if you really wanted to type _{_? Is that ever a common thing to type, in any popular framework?
Nah, I don't think it's necessary after all. (But if anyone cares about this, please comment.)
I don't immensely care, but it's worth pointing out that a person can also change the default delimiters if it comes up often enough:
Or you could simply have {{{ be interpreted as a single {, and }}} as a single }, although that'd probably mess with syntax highlighting.
For anyone else looking here I would recommend using raw blocks when working with larger jinja blocks inside cookiecutter.
E.g.:
{% raw -%}
{{ foo }} and {{ bar }}
...
{{ baz }}
{%- endraw %}
yields
{{ foo }} and {{ bar }}
...
{{ baz }}
It was useful for me when generating Ansible templates with cookiecutter.
Most helpful comment
For anyone else looking here I would recommend using raw blocks when working with larger jinja blocks inside cookiecutter.
E.g.:
yields
It was useful for me when generating Ansible templates with cookiecutter.