How to print twig variables inside html code

前端 未结 2 1344
伪装坚强ぢ
伪装坚强ぢ 2021-01-07 08:27

I created a variable, like this :

{% set checkboxHTML = \'\' %}


        
相关标签:
2条回答
  • 2021-01-07 09:16

    You have to use set, like this:

    {% set checkboxHTML = '<button class="btn btn-default btn-md" data-id="' ~ b.id ~ '">Edit</button>' %}
    

    Documentation: https://twig.symfony.com/doc/2.x/tags/set.html

    0 讨论(0)
  • 2021-01-07 09:17

    Alternative method to solve this is using the expanded {% set %}
    Do note when using this method, the content is considered being safe

    {% set checkboxHTML %}
        <button class="btn btn-default btn-md" data-id="{{ b.id }}">Edit</button>
    {% endset %}
    

    twigfiddle

    0 讨论(0)
提交回复
热议问题