Answers.Body: <p>Instead of <code>divisableby</code> I think using Twig's built-in <a href="http://twig.sensiolabs.org/doc/tests/odd.html" rel="nofollow">odd/even test</a> might be easier in this case: </p>
  
  <pre><code>{% for i in 0.. NbComment %}
  
     {% if i is odd %}
  
         &lt;!--Right comment--&gt;
  
     {% else %}
  
         &lt;!--Left comment--&gt;
  
     {% endif %}
  
  {% endfor %}
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>{% 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 %}
  </code></pre>
  
  <p>With the above code, your comments will have either the class <code>.is-odd</code> or the class <code>.is-even</code> – making it easy to e.g. float comments either <code>left</code> or <code>right</code> in your CSS. There's really no need to have a full if/else conditional.</p>
  
  <p>Also, note the <code>{% else %}</code> statement in the above <code>for</code> loop. The contained markup will output if there are no comments – which is good practice, and will save you yet another conditional :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-22T12:09:23.683Z
Answers.Text: Thanks it worked :)
  NbComment is a variable which count the number of comment i have .
  
      $nbComment = count($c) - 1;
Answers.UserDisplayName: Franck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-22T12:20:16.650Z
Answers.Text: Cool – I removed most of the answer to only contain the relevant part about using odd/even. Be advised that your loop will run (and print ```<!--Right comment-->``` even if ```NbComment``` is 0 :)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-23T18:41:37.327Z
Answers.Text: Hello @Franck, would you mind marking the above answer as accepted, if you're happy with it? Closing questions as "answered" helps keeping the site tidy and informative:)
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-03-22T11:39:13.463Z
Answers.LastActivityDate: 2015-03-22T12:16:51.450Z
Answers.LastEditDate: 2015-03-22T12:16:51.450Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>First sorry for my bad english.</p>
  
  <p>What i want to do: display comments on a page, one at the right one at the left.</p>
  
  <p>My code look like this:</p>
  
  <pre><code>{% for i in 0.. NbComment %}
     {% if  (i is divisibleby(2)) or (i == 0) %}
  
         &lt;!--Right comment--&gt;
  
     {% else %}
  
         &lt;!--Left comment--&gt;
  
     {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>It works perfectly except when I only have one comment: it display nothing.
  Thanks for your help.</p>
  
Tags: <templating><php>
Title: Twig issue with divisibleby()
ThreadText: # Twig issue with divisibleby()
  
  (Asked by: username_0 on 2015-03-22)
  
  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) %}
  
         <!--Right comment-->
  
     {% else %}
  
         <!--Left comment-->
  
     {% endif %}
  {% endfor %}
  
  ```
  
  It works perfectly except when I only have one comment: it display nothing.
  Thanks for your help.
  
  **Tags:** templating, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-03-22. Score: 2
  
  Instead of `divisableby` I think using Twig's built-in [odd/even test](http://twig.sensiolabs.org/doc/tests/odd.html) might be easier in this case:
  
  ```
  {% for i in 0.. NbComment %}
  
     {% if i is odd %}
  
         <!--Right comment-->
  
     {% else %}
  
         <!--Left comment-->
  
     {% 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 %}
  
     <div class="comment is-{% i is odd ? 'odd' : 'even' %}">
        <!-- Comment content -->
     </div>
  
  {% else %}
  
     <p class="error">No comments to display</p>
  
  {% 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 :)
  
  > **Comments:**
  > **username_0**: Thanks it worked :) NbComment is a variable which count the number of comment i have .      $nbComment = count($c) - 1;  
  > **username_1**: Cool – I removed most of the answer to only contain the relevant part about using odd/even. Be advised that your loop will run (and print ```<!--Right comment-->``` even if ```NbComment``` is 0 :)  
  > **username_1**: Hello @username_0, would you mind marking the above answer as accepted, if you're happy with it? Closing questions as "answered" helps keeping the site tidy and informative:)  
  
  ---
  
  