I created a variable, like this :
{% set checkboxHTML = '<button class="btn btn-default btn-md" data-id="{{b.id}}">Edit</button>' %}
Now I trying print in two ways:
{{ checkboxHTML }}
Above it printed like text (no html)
{{ checkboxHTML | raw }}
Print the html, but the variable {{ b.id }}
doesn't take it like twig sintax, take it like text
How to print that variable inside a text ?
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
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