I would like to create a table with different color for each even row. For that, I created the css and I will have to check in my twig template if the iteration index is even or not.
{% if loop.index == "even" %}
But how to check if a number is even in twig? Thank you.
Twig has a built in "even" test:
{% if (loop.index is even) %}
...your code here
{% endif %}
You have to use the "modulo" operator as follow :
{% if(loop.index%2 == 0) %}
...your code here
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With