在 Liquid 模板语言中,正确的注释方法是什么?
在Liquid中,您可以使用{% comment %}
和{% endcomment %}
标签进行注释:
{% comment %} This is a comment in Liquid {% endcomment %}
无论是内联评论还是块级评论都没有关系。
{% comment %}
This is a block comment in Liquid
{% endcomment %}
如果和我一样,你正在寻找一个真正将“任何”/一切都注释掉的解决方案(如文档所述),你可以使用{% 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 %}
将呈现
这里有一些文本,我希望显示,但是
{% 我不想解析的一些液体内容 %}
同时
{% comment %}
Here is some text that I don't want displayed but
{% some_liquid_stuff_that_will_be_parsed %}
{% endcomment %}
{% comment %}
{% if some test %}
some stuff to render
{% elsif... %}
unfinished code...
{% endcomment %}
{% comment %}
和{% endcomment %}
标签来留下未渲染的代码。Anything you put between {% comment %} and {% endcomment %} tags
is turned into a comment.
输出:
Anything you put between tags
is turned into a comment.
参考文档:Liquid中的注释标签
{% # This is a new inline comment! %}
{%- # This is a new inline comment without whitespace! -%}
甚至可以使用多行:
{%-
################################
# This is a really big block #
################################
-%}
更多信息可在合并的PR中获取。
{% 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 %}
{%comment%}
Text to be commented
{%endcomment%}
{% %}
的运行块中添加像/* Fnord */
这样的注释,例如{% elseif /* 做其他事情:*/ %}
。这真是令人遗憾。 - Dai{% if .. %}
这样的内容不起作用,所以它不仅啰嗦,而且有点混乱。 - Toskan