Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outputting Literal curly braces in Liquid templates

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?

like image 699
Fortes Avatar asked Jul 25 '10 20:07

Fortes


People also ask

What are the curly brackets {{ }} used for?

Curly brackets are commonly used in programming languages such as C, Java, Perl, and PHP to enclose groups of statements or blocks of code.

How do you escape curly braces?

To escape curly braces and interpolate a string inside the String. format() method use triple curly braces {{{ }}} . Similarly, you can also use the c# string interpolation feature instead of String. format().

How do you write curly braces in C?

In programming, curly braces (the { and } characters) are used in a variety of ways. In C/C++, they are used to signify the start and end of a series of statements. In the following expression, everything between the { and } are executed if the variable mouseDOWNinText is true. See event loop.

How do you match curly braces in regex Python?

"Curly braces can be used to represent the number of repetitions between two numbers. The regex {x,y} means "between x and y repetitions of something". Hence {0,1} is the same thing as ?. If the first number is missing, it is taken to be zero.


2 Answers

You can also use raw:

{% raw %}  ...lots of liquid code goes here and it doesn't get interpreted...  {% endraw %} 
like image 77
Marcel Jackwerth Avatar answered Sep 26 '22 01:09

Marcel Jackwerth


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 }} 
like image 32
MrWhite Avatar answered Sep 26 '22 01:09

MrWhite