How to escape Twig delimiters in a Twig template?

前端 未结 3 1413
不知归路
不知归路 2020-12-09 07:34

Twig uses the {{ }}, {% %}, {# #} delimiters.

But how can I display {{ }} in a Twig template? I\'m not talking ab

相关标签:
3条回答
  • 2020-12-09 07:59

    The easiest way is to output the variable delimiter ({{) by using a variable expression:

    {{ '{{' }}
    

    Alternatives (used when you have to escape too much) are raw (verbatim since 1.12) blocks:

    {% raw %}
        <ul>
        {% for item in seq %}
            <li>{{ item }}</li>
        {% endfor %}
        </ul>
    {% endraw %}
    

    Actually, it's quite well documented.

    0 讨论(0)
  • 2020-12-09 08:01
    {% block body %} 
    <table class="table table-striped"> 
        {% for temp in data %} 
        <tr> 
            <td>{{temp.fname}}</td> 
            <td>{{temp.lname}}</td> 
        </tr> 
        {% endfor %}
    </table>
    {% endblock %} 
    
    0 讨论(0)
  • 2020-12-09 08:12

    The Twig documentation gives two suggestions. The first is simply to output a string:

    {{ '{{' }}
    

    Otherwise, if you want to output a long section (it sounds like you do) you can use the raw tag:

    {% raw %}
        your mustache content here
    {% endraw %}
    
    0 讨论(0)
提交回复
热议问题