1

我正在尝试遍历导致以下结果的行:

row 1 - white
row 2 - gray
row 3 - white
row 4 - navy
row 5 - white
row 6 - gray 
row 7 - white
row 8 - navy

等等...

我有以下内容,显然只适用于前 5 行,但似乎无法找出正确的方法:

{% if loop.index is odd %}
    <div id="{{ target }}" class="band white">
{% elseif loop.index == 2 %}
    <div id="{{ target }}" class="band gray">
{% elseif loop.index == 4 %}
    <div id="{{ target }}" class="band navy">
{% endif %}

任何帮助表示赞赏。谢谢!

4

1 回答 1

2

您可能想检查循环功能,并像这样使用它:

class="band {{ cycle(["white", "gray", "white", "beige"], loop.index0) }}"
于 2018-05-19T21:17:11.163 回答