你如何评论Liquid?

时间:2014-11-19 01:21:18

标签: syntax liquid commenting

在Liquid模板语言中注释的正确方法是什么?

5 个答案:

答案 0 :(得分:79)

Liquid中,您使用{% comment %}{% endcomment %}代码发表评论:

{% comment %} This is a comment in Liquid {% endcomment %}

如果评论是内联或阻止评论,则无关紧要。

{% comment %}
    This is a block comment in Liquid
{% endcomment %}

答案 1 :(得分:2)

Liquid允许您使用... code omitted import 'bootstrap/dist/css/bootstrap.min.css'; const margin = { top: 200, right: 55, bottom: 100, left: 180}; const width = 1250 - margin.left - margin.right; const height = 800 - margin.top - margin.bottom; class Graphics extends Component { constructor(props) { super(props); } componentDidMount() { this.svg = d3.select(this.refs.container) .attr("width", width + margin.left + margin.right) .attr("height", height + margin.top + margin.bottom) .append("g") .attr( "transform", "translate(" + margin.left + "," + margin.top + ")"); this.renderOptions(); } componentDidUpdate(){ this.renderOptions(); } renderOptions(){ const keys = ["cozy","luxury","loud","modern"]; const container = d3.select(this.refs.container) .append('g') .attr('transform','translate(100,100)') .append('foreignObject') .attr('width','200px') .attr('height','200px') .append('xhtml:div') .attr('class','dropdown'); container.append('xhtml:button') .attr('class','btn btn-primary dropdown-toggle') .attr('id','dropdownMenuButton') .attr('type','button') .attr('data-toggle','dropdown') .html('Select mood') .append('xhtml:span') .attr('class','caret') container.append('xhtml:div') .attr('class','dropdown-menu') .attr('aria-labelledby','dropdownMenuButton') .selectAll('option') .data(keys) .enter() .append('xhtml:a') .attr('class','dropdown-item') .html( d => d ) } render() { return ( <main> <svg ref="container"> </svg> </main> ) } {% comment %}标签在Liquid模板中保留未渲染的代码。

输入:

{% endcomment %}

输出:

Anything you put between {% comment %} and {% endcomment %} tags
is turned into a comment.

参考文档:Comment tag in Liquid

答案 2 :(得分:1)

在液体中,使用注释标记将要注释的文本包含在注释标记

{%comment%}
Text to be commented
{%endcomment%}

答案 3 :(得分:0)

在液体中,您使用{% 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 %}

答案 4 :(得分:0)

如果像我一样,您正在寻找一种解决方案,可以实际上注释掉注释标签之间的“任何” /一切(如{{3}中所述}),您可以使用{% 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%}

有关documentation的其他信息。