I have two divs, left and right, depending on the datas retrieved from the DB I want to output it in the first or the latter one, in flat PHP it’s one of the simplest things, but using Symfony2 and TWIG it doesn’t appear this way. Here is my not-working code to let you understand better:
{% set colLeft = '' %}
{% set colRight = '' %}
{% for el in form.myCollection %}
{% if el.foo.vars.value.type == 'phone_number' %}
{% set colLeft = form_row(el.left) %}
{% else %}
{% set colRight = form_row(el.right) %}
{% endif %}
{% endfor %}
<div class="left">
{{ colLeft }}
</div>
<div class="right">
{{ colRight }}
</div>
In this way, in my final html page I see the html code and not the interpretation of it.
I also thought at writing the output to 2 files left.html.twig and right.html.twig and later to do the include, but I’m sure there’s a better way that I don’t see right now.
Any suggestion?
You must use the ‘raw’ filter :