参考になったコードをメモします。
for文で配列をループ処理
for文の基本的な使い方
{% set list = [
{'id':'01', 'title':'リスト1'},
{'id':'02', 'title':'リスト2'},
{'id':'03', 'title':'リスト3'},
{'id':'04', 'title':'リスト4'}
] %}
<ul>
{% for list in lists %}
<li class="list-{{ list.id }}">{{ list.title }}</li>
{% endfor %}
</ul>
sliceフィルターを使う方法
この例文では1〜5まで背景赤で、6〜8までが背景オレンジになる。こういう風な使い方もできる。
{% set tests = [
{'id':'01','title':'リスト1'},
{'id':'02','title':'リスト2'},
{'id':'03','title':'リスト3'},
{'id':'04','title':'リスト4'},
{'id':'05','title':'リスト5'},
{'id':'06','title':'リスト6'},
{'id':'07','title':'リスト7'},
{'id':'08','title':'リスト8'}
]%}
{%- for test in tests[:5] -%}
<p style="background: red;">{{test.id}}-{{test.title}}</p>
{%- endfor -%}
{%- for test in tests[5:] -%}
<p style="background: orange;">{{test.id}}-{{test.title}}</p>
{%- endfor -%}
条件文も指定できる
{% for i in 1..10 if i % 2 == 0 %}
{{ i }},
{% endfor %}
{# 2, 4, 6, 8, 10, #}
参考になったコードは随時記載していきます!