Skip to content

Instantly share code, notes, and snippets.

@jpetitcolas
Created January 8, 2013 06:29
Show Gist options
  • Save jpetitcolas/4481722 to your computer and use it in GitHub Desktop.
Save jpetitcolas/4481722 to your computer and use it in GitHub Desktop.
How to differenciate odd and even rows with Twig?
<table>
{% for record in records %}
<tr class="record{% if loop.index is divisibleby(2) %}even{% else %}odd{% endif %}">
<td>{{ record.id }}</td>
<td>{{ record.title }}</td>
</tr>
{% endfor %}
</table>
@marlisa31
Copy link

this works too:

{% if loop.index is even %} ... {% else %} ... {% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment