Forloop

Forloop

Forloop

Properties of Forloop objects
Name Type Description
name String The name of the current forloop (automatically generated from the for tag's variable and collection names).
length Number The number of items in the forloop
index Number The 1-based index of the current item in the for loop.
index0 Number The 0-based index of the current item in the for loop.
rindex Number The 1-based index of the current item in the for loop counting from the end to the beginning (the reverse of index).
rindex0 Number The 0-based index of the current item in the for loop counting from the end to the beginning (the reverse of index0).
first Boolean True if the current item is the first item in the for loop.
last Boolean True if the current item is the last item in the for loop.

Related

string

Can be any text, from the empty string ("") to the full HTML output of the template. When used alone in a conditional, all strings evaluates as true - even if they are empty or a value such as "0" or "false".

number

Can be any number, including integers, decimals, or the value 0. Any value - including 0 - evaluates as true when used alone in a conditional.

{{ tag }}

boolean

True or False

{% for %}

Iterates through every item in a list. Executes and outputs a block of code to the template for each item in the list.

{% for item in collection reversed? [limit:num]? [offset:value]? %}

{% for
variable_name
 
The name for the variable to assign each item in the collection to
in
collection
 
One or more values. May use the variable arguments syntax. The list of items to iterate
reversed
 
If true, the items will be iterated in reverse order. Note that this takes effect after the offset and limit are applied
limit
offset
 
The number of items to skip at the beginning of the list. Alternatively, use the keyword "continue" to resume iteration of the list from the last time the same item and collection names were used in a for loop
%}

{% else %}

{% else %}

If there are no items to iterate, the "else" block will be executed and output instead. This may be for several reasons, such as if the collection is not a list or is empty, or if the offset is greater than the size of the list.

{% continue %}

{% continue %}

Skips to the next iteration of the current loop.

{% break %}

{% break %}

Exits the current loop immediately.

{% endfor %}

This method creates a new liquid context for storing and manipulating variables.

Related

{% gallery %}

{% articles %}