代码之家  ›  专栏  ›  技术社区  ›  Fortes

在液体模板中输出文本大括号

  •  29
  • Fortes  · 技术社区  · 15 年前

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

    {{ example }}
    

    显然,Liquid将其视为一个名为 example 试图做替代品。我想知道如何输出实际的大括号。

    到目前为止,我已经找到了一种可行的方法,但它非常丑陋:

    {{ '{example'|prepend:'{' }}}}
    

    是的,告诉过你这很恶心。

    以下是我尝试过的其他方法:

    {{{ example }}}     # outputs '}'
    {{{{ example }}}}   # outputs '}}'
    \{\{ example \}\}   # outputs '\{\{ example \}\}'
    

    有什么建议吗?

    4 回复  |  直到 9 年前
        1
  •  10
  •   MrWhite    15 年前

    使用数字HTML实体怎么样 { } 对于 { } 分别-假设这是输出为HTML?

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

    {% assign special = '{{ example }}' %}
    {{ special }}
    
        2
  •  105
  •   Community Mohan Dere    13 年前

    您也可以使用 raw :

    {% raw %}
    
    ...lots of liquid code goes here and it doesn't get interpreted...
    
    {% endraw %}
    
        3
  •  0
  •   Community Mohan Dere    9 年前

    这是我唯一能做的事。从提升 here :

    {{ "{{ this " }}}}
    

    我需要这个因为我想引用 site 来自mustache模板内部的全局变量。

        4
  •  -3
  •   Yeison Agudelo    9 年前

    例如,您可以在 {{var}} 你可以使用 \{\{var\}\} 这样Luquid就不会处理它了。