Contains properties useful within a for loop block.

  forloop can only be used within a for tag.
Code
{% for child in page.children %}
{% if forloop.first %}
This is the first child page!
{% else %}
This is child page number {{ forloop.index }}.
{% endif %}
{% endfor %}
Output
This is the first child page!
This is child page number 2.
This is child page number 3.

Attributes

first

Returns true if it's the first iteration of the loop. Returns false if it's not the first iteration.

index

The current item's position in the collection, where the first item has a position of 1.

index0

The current item's position in the collection, where the first item has a position of 0.

last

Returns true if it's the last iteration of the loop. Returns false if it's not the last iteration.

length

Returns the number of iterations for the loop – the number of items in the collection being iterated over.

rindex

Number of items remaining in the loop (length - index) where 1 is the index of the last item.

rindex0

Number of items remaining in the loop (length - index) where 0 is the index of the last item.