Let's say items
contains ["a", "b", "c", "d", "e"]
, then something like this:
{% for item in items %}
{{forloop.index | modulo: 2}} -> {{item}}
{% endfor %}
would produce:
1 -> a
0 -> b
1 -> c
0 -> d
1 -> e
Question
I need to loop through an array of items, alternating between two different background colors as I go. Is there a way to do this in liquid markup?
La solution
Let's say items
contains ["a", "b", "c", "d", "e"]
, then something like this:
{% for item in items %}
{{forloop.index | modulo: 2}} -> {{item}}
{% endfor %}
would produce:
1 -> a
0 -> b
1 -> c
0 -> d
1 -> e