在Liquid模板中输出文字大括号 [英] Outputting Literal curly braces in Liquid templates

查看:188
本文介绍了在Liquid模板中输出文字大括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

{{ example }}

很明显,Liquid将其视为名为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 \}\}'

这里有什么建议吗?

推荐答案

分别对{}使用数字HTML实体{}怎么办?大概是将其输出为HTML?

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

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

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 }}

这篇关于在Liquid模板中输出文字大括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆