I have an error comparing two strings
in twig
.
Here is an example of my code:
{% set var1 = "" %}
{% set var2 = "" %}
{% for unidad in array %}
{% if unidad.var1 == var1 %}
{% if unidad.var2 == var2 %}
<tr>
<td>{{ habitacion.var1 }}</td>
<td>{{ habitacion.var2 }}</td>
</tr>
{% else %}
<tr><td>---</td><td>---</td></tr>
{% endif %}
{% else %}
<tr>
<td>|{{ unidad.var1 }}| |{{ var1 }}|</td>
<td>|{{ unidad.var2 }}| |{{ var2 }}|</td>
</tr>
{% endif %}
{% set var1 = unidad.var1 %}
{% set var2 = unidad.var2 %}
{% endfor %}
The problem is that the loop does not enter the if
, with the two variables being the same in some cases. I show you the output screen in a loop loop that does not enter the if
:
<td>|NORMAL| |NORMAL|</td>
<td>|311| |311|</td>
I have also tried to put the if
in this way:
{% if unidad.var1 is same as(var1) %}
But it does not work either.