Answer the question
In order to leave comments, you need to log in
Twig - different output of even and odd posts?
You need to output posts in the specified format, how to do it using Twig inside the loop: {% for post in posts %}
(how to create a variable and check its parity?)
Answer the question
In order to leave comments, you need to log in
Found what I was looking for - Twig has a special parity check construct
{% if var is even%}
...
{% endif %}
{% if var is odd%}
...
{% endif %}
You can use the cycle
function , and use it to add the row__even and row__odd classes, and style it through css.
{% for post in posts %}
<div class="row row__{{ cycle(['even', 'odd'], loop.index0) }}">
</div>
{% endfor %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question