这听起来很简单,但是我在文档中找不到它。如何在不被引擎处理的情况下,在liquid模板中编写{% this %}
?
使用raw
标签可以禁用Liquid处理引擎:
{% raw %}
{% this %}
{% endraw %}
会显示
{% this %}
raw
标签。请参见 https://github.com/Shopify/liquid/commits/master/lib/liquid/tags/raw.rb - Etienneraw
标签是在Liquid 2.3.0中引入的(见链接),而GitHub Pages目前正在使用版本2.5.5。 - Enrico Campidoglio{% endraw %}
,{% raw %}{% endraw %}{% raw %}
将不会被渲染。 - tartaruga_casco_mole对于未来的搜索者而言,有一种无需插件即可进行转义的方法,使用下面的代码:
{{ "{% this " }}%}
对于标签,要转义 {{ this }}
使用:
{{ "{{ this " }}}}
还有一个Jekyll插件,使这个过程变得更加容易:https://gist.github.com/1020852
jekyll的原始标签。保持 Liquid 不解析 {% raw %} 和 {% endraw %} 之间的文本。
{% raw %}{{ this }}{% endraw %}
。 - Yevgeniy Brikman您可以使用 {% raw %} {% endraw %} 来转义 Jekyll 文章中的液态标签,即:
{% raw %}
{% for post in site.posts %}
{{ post.content }}
{% endfor %}
{% endraw %}
将会产生
{% for post in site.posts %}
{{ post.content }}
{% endfor %}
顺便说一句:
如果你想在Jekyll中显示{{ "{% this " }}%}
,可以像这样编码:
{{ "{{ " }}"{{ "{% this" }} " }}{{ "}}%}
要转义{{ "{{ this " }}}}
,请使用:
{{ "{{ " }}"{{ "{{ this" }} " }}{{ "}}}}
还有另一种选择:使用HTML特殊字符编码来替换花括号与其对应的编码:
- 用{替换每个{
- 用}替换每个}
有关此解决方案的更多详细信息,请参见: http://www.tikalk.com/devops/curly_brances_workaround/
{% assign var = "{{ sth }}" %}
{{ var }}
{% raw %}
和 {% endraw %}
只是第二好的解决方案,因为如果你在普通的github.com上查看Markdown,它们会被显示出来。{% raw %}
和{% endraw %}
放在HTML注释中:<!-- {% raw %} -->
something with curlky brackets like { this } and { that }
<!-- {% endraw %} -->
我尝试过使用{% raw %}
和{% endraw %}
,
以及{{ "{% this " }}%}
,但它们都无法正常工作。
最终,我的可行答案是{{ "{%" xxx }} something }}
。
我的代码:
{{ "{%" }} extends 'xadmin/base_site.html' %}
{{ "{%" }} block nav_form %}
<h3>{{ "{{" }} title }}</h3>
{{ "{%" }} for i in context1 %}
<p>{{ "{{" }} i }}</p>
{{ "{%" }} endfor %}
{{ "{%" }} endblock %}
{% extends 'xadmin/base_site.html' %}
{% block nav_form %}
<h3>{{ title }}</h3>
{% for i in context1 %}
<p>{{ i }}</p>
{% endfor %}
{% endblock %}
允许在页面上输出 Liquid 代码而不进行解析。
{% raw %}{{ 5 | plus: 6 }}{% endraw %} equals 11.
{{ 5 | plus: 6 }} equals 11.
有关此解决方案的更多详细信息,请参见:https://www.shoplazza.dev/docs/theme-tags