Outputting Literal curly braces in Liquid templates

Viewed 9263

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 Answers

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>

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

Related