Iteracijos žymės
Iteracijos žymės naudojamos kodo blokui paleisti / atvaizduoti kelis kartus.
for
Vykdo kodo bloką kelis kartus. Jis dažniausiai naudojamas kartoti masyvo ar žodyno elementus.
Žymės bloke galimas besąlygis objektas.
Kodas
{% for child_page in page.children %}
<a href={{ child_page.url }}>{{ child_page.title }}</a>
{% endfor %}
Išvesties
<a href=/parent/child1/>Child 1</a>
<a href=/parent/child2/>Child 2</a>
<a href=/parent/child3/>Child 3</a>
Parametrai
Šiuos „for“ parametrus galima naudoti vienus arba kartu.
riba
Baigia ciklą pasiekus tam tikrą elementų skaičių.
Kodas
{% for child_page in page.children limit:2 %}
<a href={{ child_page.url }}>{{ child_page.title }}</a>
{% endfor %}
Išvesties
<a href=/parent/child1/>Child 1</a>
<a href=/parent/child2/>Child 2</a>
Kompensuoti
Pradeda ciklą ties tam tikra rodykle.
Kodas
{% for child_page in page.children offset:1 %}
<a href={{ child_page.url }}>{{ child_page.title }}</a>
{% endfor %}
Išvesties
<a href=/parent/child2/>Child 2</a>
<a href=/parent/child3/>Child 3</a>
Diapazonas
Apibrėžia skaičių, kurių ciklas vykdomas, diapazoną.
Kodas
{% assign n = 4 %}
{% for i in (2..n) %}
{{ i }}
{% endfor %}
{% for i in (10..14) %}
{{ i }}
{% endfor }}
Išvesties
2 3 4
10 11 12 14
Atšauktas
Kartoja ciklą atvirkštine tvarka, pradedant nuo paskutinio elemento.
Kodas
{% for child_page in page.children reversed %}
<a href={{ child_page.url }}>{{ child_page.title }}</a>
{% endfor %}
Išvesties
<a href=/parent/child3/>Child 3</a>
<a href=/parent/child2/>Child 2</a>
<a href=/parent/child1/>Child 1</a>
ciklas
Vykdo eilučių grupės ciklą ir pateikia jų išvestį tokia tvarka, kokia jos buvo perduotos kaip parametrai. Kiekvieną kartą iškvietus ciklą, kita eilutė, perduota kaip parametras yra išvestis.
Kodas
{% for item in items %}
<div class={% cycle 'red', 'green', 'blue' %}> {{ item }} </div>
{% end %}
Išvesties
<div class=red> Item one </div>
<div class=green> Item two </div>
<div class=blue> Item three </div>
<div class=red> Item four </div>
<div class=green> Item five</div>
tablerow
Generuoja HTML lentelės vaizdą. Turi būti tarp pradžios <table> ir pabaigos </table> HTML žymių.
Žymės bloke „tablerow“ yra tablerowloop.
Kodas
<table>
{% tablerow child_page in page.children %}
{{ child_page.title }}
{% endtablerow %}
</table>
Išvesties
<table>
<tr class=row1>
<td class=col1>
Child Page 1
</td>
<td class=col2>
Child Page 2
</td>
<td class=col3>
Child Page 3
</td>
<td class=col4>
Child Page 4
</td>
</tr>
</table>
Parametrai
Šiuos „tablerowcan“ parametrus galima naudoti vienus arba kartu.
Išvesties
<table>
<tr class=row1>
<td class=col1>
Child Page 1
</td>
<td class=col2>
Child Page 2
</td>
</tr>
<tr class=row2>
<td class=col3>
Child Page 3
</td>
<td class=col4>
Child Page 4
</td>
</tr>
</table>
Kodas
<table>
{% tablerow child_page in page.children cols:2 %}
{{ child_page.title }}
{% endtablerow %}
</table>
Diktuoja, kiek eilučių turėtų būti lentelėje, kurios vaizdas generuojamas.
kolsai
riba
Baigia ciklą pasiekus tam tikrą elementų skaičių.
Kodas
<table>
{% tablerow child_page in page.children limit:2 %}
{{ child_page.title }}
{% endtablerow %}
</table>
Išvesties
<table>
<tr class=row1>
<td class=col1>
Child Page 1
</td>
<td class=col2>
Child Page 2
</td>
</tr>
</table>
offset
Pradeda ciklą ties tam tikra rodykle.
Kodas
<table>
{% tablerow child_page in page.children offset:2 %}
{{ child_page.title }}
{% endtablerow %}
</table>
Išvesties
<table>
<tr class=row1>
<td class=col1>
Child Page 3
</td>
<td class=col2>
Child Page 4
</td>
</tr>
</table>
Diapazonas
Apibrėžia skaičių, kurių ciklas vykdomas, diapazoną.
Kodas
<table>
{% tablerow i in (1..3) %}
{{ i }}
{% endtablerow %}
</table>