如何在树枝中使用单注释行和多注释行

MaT*_*evi 1 symfony twig

我是树枝项目的新手。我需要注释一些代码,例如 // 或 /**/。如何在树枝中使用评论?

    {%if role=3 %}
<div class="col-md-6">
        <div class="form-group">
           <label class="control-label">&nbsp;</label>
           <select multiple class="form-control"  id="path_attachment" name="path_attachment[]"></select>
        </div>
</div>
{% else %}
<div class="col-md-6"></div>
{% endif %}
Run Code Online (Sandbox Code Playgroud)

sco*_*ico 10

{# Commented Code in Twig #}
Run Code Online (Sandbox Code Playgroud)

希望它能帮助你。


Muj*_*iya 7

评论 :)

注释掉一行或多行代码(或一行的一部分)

使用 {# ..... #} 语法。

例如:

单行注释:

{# This will be a comment #}
Run Code Online (Sandbox Code Playgroud)

该行的某些部分:

<p>You can also comment out {# part of a line #}.</p>
Run Code Online (Sandbox Code Playgroud)

多行注释:

{# This will be a 
multi-line
comment. 
#}
Run Code Online (Sandbox Code Playgroud)

注释不仅仅对于编写代码注释有用。您还可以导致代码块不被执行。注释标签之间的任何Twig代码都不会被执行或输出。

{# The following code will not be executed and nothing will be outputted
{% if category.posts %}
    This category has posts
{% endif %}
#}
Run Code Online (Sandbox Code Playgroud)


小智 6

twig 命令关键字是#。在 {# 内部使用并以 #} 结尾。以下是您需要的答案。

    {#%if role=3 %}
<div class="col-md-6">
        <div class="form-group">
           <label class="control-label">&nbsp;</label>
           <select multiple class="form-control"  id="path_attachment" name="path_attachment[]"></select>
        </div>
</div>
{% else %}
<div class="col-md-6"></div>
{% endif %#}
Run Code Online (Sandbox Code Playgroud)