Set dynamic class in for Loop I have this simple element model and I'm trying to add dynamic class within loop.
So every time a model outputs, It outputs dynamic class. Can't go for another loop within loop, in case I could, therefor It'd be easy.

            {% set tags = slide.foodTags %}
            {% if tags %} 

            &lt;div&gt;   
                  {% for tag in tags %}                     
                        &lt;span class="{# dynamic-class #}"&gt;
                            {{ tag.title }}
                        &lt;/span&gt;
                  {% endfor %}
            &lt;/div&gt; 

           {% endif %}
I can't comment yet to reply directly to Mats Mikkel Rummelhoff's comment above, but just in case someone comes across this and is looking to alternate styles instead of basing it on the loop.index count.

You would do so using the Twig odd or even tests

{{ loop.index is odd ? 'odd' : 'even' }}


or

{{ loop.index is even ? 'even' : 'odd' }}


There is no loop.odd key