forloop
Information about a parent for loop.
Properties
The parent
forloopobject.If the current
forloop isn't nested inside anotherforloop, thennilis returned.ExampleUse theparentloopproperty{% for i in (1..3) -%}{% for j in (1..3) -%}{{ forloop.parentloop.index }} - {{ forloop.index }}{%- endfor %}{%- endfor %}Code
{% for i in (1..3) -%} {% for j in (1..3) -%} {{ forloop.parentloop.index }} - {{ forloop.index }} {%- endfor %} {%- endfor %}Output
1 - 11 - 21 - 32 - 12 - 22 - 33 - 13 - 23 - 3
{
"first": true,
"index": 1,
"index0": 0,
"last": false,
"length": 4,
"rindex": 3
}
Example
{
"first": true,
"index": 1,
"index0": 0,
"last": false,
"length": 4,
"rindex": 3
}Anchor to Use the `forloop` object
Use the forloop object
forloop object{% for page in pages -%}
{%- if forloop.length > 0 -%}
{{ page.title }}{% unless forloop.last %}, {% endunless -%}
{%- endif -%}
{% endfor %}
Code
{% for page in pages -%}
{%- if forloop.length > 0 -%}
{{ page.title }}{% unless forloop.last %}, {% endunless -%}
{%- endif -%}
{% endfor %}Output
About us, Contact, Potion dosages
Was this section helpful?