33
votes

I'm trying to output the following from within a liquid template:

{{ example }}

Obviously, Liquid sees this as a variable named example and tries to do substitution. I'm trying to find out how I can output the actual braces.

So far, I've found one method that works, but it's incredibly ugly:

{{ '{example'|prepend:'{' }}}}

Yeah, told you it was gross.

Here are other things I've tried:

{{{ example }}}     # outputs '}'
{{{{ example }}}}   # outputs '}}'
\{\{ example \}\}   # outputs '\{\{ example \}\}'

Any advice here?

5
Aside from the 'raw/endraw' answer with the most votes below, also check out "How to escape liquid template tags?" that offers a commenting out type solution.Alan W. Smith
Does this answer your question? How to escape liquid template tags?Jon Ericson

5 Answers

141
votes

You can also use raw:

{% raw %}

...lots of liquid code goes here and it doesn't get interpreted...

{% endraw %}
9
votes

What about using the numeric HTML entities { and } for { and } respectively - presumably this is to be output as HTML?

EDIT: Forgive me, I'm not too familiar with liquid (so this might be very wrong), but can you assign your {{ example }} special value to a variable and output that? May be something like:

{% assign special = '{{ example }}' %}
{{ special }}
2
votes

This is the only thing that worked from me. Lifted from here:

{{ "{{ this " }}}}

I needed this because I wanted to reference the site global variable from inside a mustache template.

0
votes

I wanted to have both curly brackets AND angle brackets when formatting a fenced code block, so I ended up with the following pattern:

{% capture code %}{% raw %}line 1
line 2
line 3
{% endraw %}{% endcapture %}

<pre><code>{{ code | replace: "<", "&lt;" | replace: ">", "&gt;" }}</code></pre>
-3
votes

You can escape the HTML, for example in a {{var}} you can use \{\{var\}\}, so that way luquid don't process it.