How do you comment out in Liquid?

前端 未结 5 1822
轻奢々
轻奢々 2020-12-29 00:48

What is the correct way to comment out in the Liquid templating language?

相关标签:
5条回答
  • 2020-12-29 01:29

    In liquid, you use {% comment %} and {% endcomment %} tags:

    {% 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 %}
        <div class="commented_out">
        <p>This whole div would be commented out</p>
        </div>
    {% endcomment %}
    
    0 讨论(0)
  • 2020-12-29 01:33

    In the liquid, using comment tag enclose the text to be commented inside the comment tag

    {%comment%}
    Text to be commented
    {%endcomment%}
    
    0 讨论(0)
  • 2020-12-29 01:34

    Liquid allows you to leave un-rendered code inside a Liquid template by using the {% comment %} and {% endcomment %} tags.

    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

    0 讨论(0)
  • 2020-12-29 01:45

    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), e.g.

    {% 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 %}

    Additional information on this GitHub thread.

    0 讨论(0)
  • 2020-12-29 01:47

    In Liquid you comment out using the {% comment %} and {% endcomment %} tags:

    {% 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 %}
    
    0 讨论(0)
提交回复
热议问题