| 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. |
string
number
{{ tag }}
boolean
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]? %}
{% 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 %}
Skips to the next iteration of the current loop.
{% break %}
Exits the current loop immediately.
{% endfor %}
This method creates a new liquid context for storing and manipulating variables.
{% gallery %}
{% articles %}
How to use the for method
CopyBasic: iterate through a collection
Use the forloop variables to access loop properties
Watch out for nested forloop variables
Correcting access to nested forloop variables
For loop with limit, and the continue keyword
For loop reversed
For loop with numeric offset
Demonstrates how to looping collection and accessing forloop properties.
Looping collection and accessing forloop properties
CopyDemonstrates how to loop Post Parameters.
Loop Post Parameters
CopyDemonstrates how to to map a collection of entities into a human-readable list of titles linking to the entities
Display linked titles from a list of items
CopyThe linked_title property is a shortcut to output the entity title, optionally inside a link if the entity has a url. This example takes it one step further by outputting the list according to common English usage - as a comma-separated list with the last item preceeded by "and" and handling lists with only one or two items appropriately. If there are no items in the list, then the output is "(none)".
Demonstrates how to list all keys and values for a labels field.
List all keys and values for a labels field
Copy