【发布时间】:2015-01-16 09:49:15
【问题描述】:
在 Liquid 模板语言中注释掉的正确方法是什么?
【问题讨论】:
在 Liquid 模板语言中注释掉的正确方法是什么?
【问题讨论】:
在Liquid 中,您使用{% comment %} 和{% endcomment %} 标签注释掉:
{% comment %} This is a comment in Liquid {% endcomment %}
注释是内联注释还是块注释都没有关系。
{% comment %}
This is a block comment in Liquid
{% endcomment %}
【讨论】:
{% %} 运行中执行类似/* Fnord */ 行的操作,例如{% elseif /* do the other thing:*/ %}。真可惜。
{% if .. %} ,所以它不仅冗长,而且有点垃圾
在液体中,使用评论标签将要评论的文本包含在评论标签内
{%comment%}
Text to be commented
{%endcomment%}
【讨论】:
Liquid 允许您使用 {% comment %} 和 {% endcomment %} 标签将未渲染的代码留在 Liquid 模板中。
输入:
Anything you put between {% comment %} and {% endcomment %} tags
is turned into a comment.
输出:
Anything you put between tags
is turned into a comment.
【讨论】:
在液体中,您使用{% comment %} 和{% endcomment %} 标签:
{% comment %} This would be commented out {% endcomment %}
你也可以在块中使用它:
{% comment %}
This would also be commented out
{% endcomment %}
如果 {% comment %} 和 {% endcomment %} 标记会注释任何内容,包括 HTML 元素等:
{% comment %}
<div class="commented_out">
<p>This whole div would be commented out</p>
</div>
{% endcomment %}
【讨论】:
如果像我一样,您正在寻找一个实际上在评论标签之间“anything”/everything的解决方案(如documentation中所述) ,您可以使用{% raw %} 标签(如果您不想在浏览器中呈现任何内容,请与{% comment %} 标签结合使用),例如
{% comment %}
{% raw %}
Here is some text that I don't want displayed and
{% some_liquid_stuff_that_I_don't_want_parsed %}
{% endraw %}
{% endcomment %}
什么都不渲染,而
{% raw %}
Here is some text that I want displayed but
{% some_liquid_stuff_that_I_don't_want_parsed %}
{% endraw %}
将渲染
这是我想要显示的一些文本,但是
{% some_liquid_stuff_that_I_don't_want_parsed %}
关于this GitHub thread的更多信息。
【讨论】: