在Liquid模板中输出文字花括号

For*_*tes 31 templates liquid

我正在尝试从液体模板中输出以下内容:

{{ example }}
Run Code Online (Sandbox Code Playgroud)

显然,Liquid认为这是一个名为变量example并尝试进行替换.我试图找出如何输出实际的大括号.

到目前为止,我发现了一种有效的方法,但它非常难看:

{{ '{example'|prepend:'{' }}}}
Run Code Online (Sandbox Code Playgroud)

是的,告诉你这很糟糕.

以下是我尝试过的其他事情:

{{{ example }}}     # outputs '}'
{{{{ example }}}}   # outputs '}}'
\{\{ example \}\}   # outputs '\{\{ example \}\}'
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

Mar*_*rth 118

你也可以使用raw:

{% raw %}

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

{% endraw %}
Run Code Online (Sandbox Code Playgroud)

  • 这应该是公认的答案。以下在脚本模板中非常适合我:`moneyFormat: {% raw %}'${{amount_no_decimals}}'{% endraw %}` (3认同)

MrW*_*ite 10

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

编辑:原谅我,我不太熟悉液体(所以这可能是非常错误的),但你可以将你的{{ example }}特殊值分配给变量并输出吗?可能是这样的:

{% assign special = '{{ example }}' %}
{{ special }}
Run Code Online (Sandbox Code Playgroud)