문제

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?

도움이 되었습니까?

해결책

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top