I want to optimize my source code Twig but this does not look very efficient to me.
My code :
{% for info in infos %}
{% set i = 0 %}
{% if loop.index0 is divisibleby(3) %}
<div class="row-fluid">
<ul class="thumbnails">
{% set open = 'yes' %}
{% endif %}
<li class="span4">
<div class="thumbnail">
<img src="#" alt="">
<div class="caption">
<h4>{{ info.titre }}</h4>
<p>{{ info.text }}</p>
<p><a href="#" class="btn btn-primary">{# a traduire multi #}Lire</a></p>
</div>
</div>
</li>
{% if loop.index is divisibleby(3) and open == 'yes' %}
</ul>
</div>
{% endif %}
{% endfor %}
How can I avoid creating so many variables, and using the same condition twice?
Maybe the following does not work, but I hope you get the idea: