35

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?

Fortes
  • 1,436
  • 2
  • 12
  • 14
  • 2
    Aside from the 'raw/endraw' answer with the most votes below, also check out "[How to escape liquid template tags?](http://stackoverflow.com/q/3426182/102401)" that offers a commenting out type solution. – Alan W. Smith Sep 08 '13 at 22:01
  • Does this answer your question? [How to escape liquid template tags?](https://stackoverflow.com/questions/3426182/how-to-escape-liquid-template-tags) – Jon 'links in bio' Ericson Apr 08 '21 at 18:01

5 Answers5

147

You can also use raw:

{% raw %}

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

{% endraw %}
Community
  • 1
  • 1
Marcel Jackwerth
  • 53,948
  • 9
  • 74
  • 88
9

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 }}
MrWhite
  • 43,179
  • 8
  • 60
  • 84
  • Unfortunately, the output is ultimately going to be within a – Fortes Jul 25 '10 at 21:20
  • @Fortes I've updated my answer: can you assign your string with braces to a variable and output that instead? – MrWhite Jul 25 '10 at 22:10
  • Uh, is this the only way to display Liquid syntax in Liquid itself? I'm trying to display a whole template on a page that is generated with Liquid and it's messed up badly right now. Is there nothing like {{noparsefromhere}}...{{noparsetohere}}? – cringe Sep 15 '10 at 19:09
  • @cringe I would agree - there _should_ be a way. But I'm no expert with Liquid I'm afraid! Can you for instance load your entire _sub template_ (that you want to display as-is) into a template variable (without it being parsed) and display your variable in the main template? Or does that still get parsed? – MrWhite Sep 16 '10 at 12:16
  • @w3d Hm, that sounds like a way to do it... I don't know yet if I can load a whole template. But I think it's easier for me to just provide the actual template in source format and link to it directly. – cringe Sep 18 '10 at 10:08
2

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.

Community
  • 1
  • 1
Richard Nienaber
  • 10,324
  • 6
  • 55
  • 66
0

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>
David Foster
  • 6,931
  • 4
  • 41
  • 42
-4

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