Twig issue with divisibleby() First sorry for my bad english.

What i want to do: display comments on a page, one at the right one at the left.

My code look like this:

{% for i in 0.. NbComment %}
   {% if  (i is divisibleby(2)) or (i == 0) %}

       &lt;!--Right comment--&gt;

   {% else %}

       &lt;!--Left comment--&gt;

   {% endif %}
{% endfor %}


It works perfectly except when I only have one comment: it display nothing.
Thanks for your help.
Instead of divisableby I think using Twig's built-in odd/even test might be easier in this case: 

{% for i in 0.. NbComment %}

   {% if i is odd %}

       &lt;!--Right comment--&gt;

   {% else %}

       &lt;!--Left comment--&gt;

   {% endif %}

{% endfor %}


And, just to suggest some minor improvements to your Twig, assuming the only difference between your comments is their alignment (left/right), you could do something like this, which would probably be a bit more DRY:

{% for i in 0.. NbComment %}

   &lt;div class="comment is-{% i is odd ? 'odd' : 'even' %}"&gt;
      &lt;!-- Comment content --&gt;
   &lt;/div&gt;

{% else %}

   &lt;p class="error"&gt;No comments to display&lt;/p&gt;

{% endfor %}


With the above code, your comments will have either the class .is-odd or the class .is-even – making it easy to e.g. float comments either left or right in your CSS. There's really no need to have a full if/else conditional.

Also, note the {% else %} statement in the above for loop. The contained markup will output if there are no comments – which is good practice, and will save you yet another conditional :)