Pergunta

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?

Foi útil?

Solução

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top