[英]How do you comment out in Liquid?
用 Liquid 模板语言注释掉的正确方法是什么?
In Liquid you comment out using the {% comment %}
and {% endcomment %}
tags:在Liquid中,您使用
{% comment %}
和{% endcomment %}
标签注释掉:
{% comment %} This is a comment in Liquid {% endcomment %}
It doesn't matter if the comment is inline or a block comment.注释是内联注释还是块注释都没有关系。
{% comment %}
This is a block comment in Liquid
{% endcomment %}
Liquid allows you to leave un-rendered code inside a Liquid template by using the {% comment %}
and {% endcomment %}
tags. Liquid 允许您使用
{% comment %}
和{% endcomment %}
标签将未渲染的代码留在 Liquid 模板中。
Input:输入:
Anything you put between {% comment %} and {% endcomment %} tags
is turned into a comment.
Output:输出:
Anything you put between tags
is turned into a comment.
Reference documentation: Comment tag in Liquid参考文档: Liquid 中的注释标签
If, like me, you are looking for a solution that actually comments out "anything"/everything between the comment tags (as described in the documentation ), you can use the {% raw %}
tag (in conjuction with the {% comment %}
tag if you don't want anything rendered in the browser), eg如果像我一样,您正在寻找一个实际上注释掉评论标签之间的“任何东西”/所有东西的解决方案(如文档中所述),您可以使用
{% raw %}
标签(与{% comment %}
结合使用) {% 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 %}
will render nothing at all, while什么都不会渲染,而
{% raw %}
Here is some text that I want displayed but
{% some_liquid_stuff_that_I_don't_want_parsed %}
{% endraw %}
will render将呈现
Here is some text that I want displayed but
这是我想要显示的一些文本,但是
{% some_liquid_stuff_that_I_don't_want_parsed %}
{% some_liquid_stuff_that_I_don't_want_parsed %}
Additional information on this GitHub thread .有关此 GitHub 线程的其他信息。
In liquid, you use {% comment %}
and {% endcomment %}
tags:在液体中,您使用
{% comment %}
和{% endcomment %}
标签:
{% comment %} This would be commented out {% endcomment %}
You can also use it in block:您也可以在块中使用它:
{% comment %}
This would also be commented out
{% endcomment %}
If the {% comment %}
and {% endcomment %}
tags would comment anything, including HTML elements and such:如果
{% comment %}
和{% endcomment %}
标签会评论任何内容,包括 HTML 元素等:
{% comment %}
<div class="commented_out">
<p>This whole div would be commented out</p>
</div>
{% endcomment %}
In the liquid, using comment tag enclose the text to be commented inside the comment tag在液体中,使用评论标签将要评论的文本包含在评论标签内
{%comment%}
Text to be commented
{%endcomment%}
Starting with Liquid 5.4.0 you will be able to use a short inline comment that does not require a closing tag!从 Liquid 5.4.0 开始,您将能够使用不需要结束标记的简短内联注释! The syntax is:
语法是:
{% # This is a new inline comment! %}
As with other tags you can add hyphens to remove whitespace around it:与其他标签一样,您可以添加连字符以删除其周围的空格:
{%- # This is a new inline comment without whitespace! -%}
And even use multiple lines:甚至使用多行:
{%-
################################
# This is a really big block #
################################
-%}
More info is available in the merged PR .合并后的 PR中提供了更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.