I have this code:
{% for entry in craft.entries.section('gigs') %}
<h2 class="{{ cycle(['odd','even'], loop.index0) }}">{{ entry.title }}</h2>
{% endfor %}
This returns the same cycles for the last two entries like so:
<h2 class="odd">Title 1</h2>
<h2 class="even">Title 2</h2>
<h2 class="odd">Title 3</h2>
<h2 class="even">Title 4</h2>
<h2 class="odd">Title 5</h2>
<h2 class="odd">Title 6</h2>
No matter how many entries, the last two entries have always the same class. Why is that?
Edit: Okay, I figured the problem. It's not a bug:
I filter the entries by date:
{% set present = now|date_modify("-1 day") %}
{% for entry in craft.entries.section('gigs') %}
{% if entry.datum < present %}
<h2 class="{{ cycle(['odd','even'], loop.index0) }}">{{ entry.title }</h2>
{% endif %}
{% endfor %}
so the cycle filter works, but since some entries are filtered the odd/even schema doesn't work any longer. I guess I have to filter the entries first and then apply the cycle filter. But how would I have to write do that?
{{ loop.index0 }}
— I believe that is what determines which value is ultimately used. – Douglas McDonald Feb 8 '15 at 16:55