Iteration
Iteration tags repeatedly run blocks of code.
for
Repeatedly executes a block of code. For a full list of attributes available within a for
loop, refer to the forloop
object.
Input
Output
else
Specifies a fallback case for a for
loop which will run if the loop has zero length.
Input
Output
break
Causes the loop to stop iterating when it encounters the break
tag.
Input
Output
continue
Causes the loop to skip the current iteration when it encounters the continue
tag.
Input
Output
for (parameters)
limit
Limits the loop to the specified number of iterations.
Input
Output
offset
Begins the loop at the specified index.
Input
Output
To start a loop from where the last loop using the same iterator left off, pass the special word continue
.
Input
Output
range
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers, and can be pulled from a variable.
Input
Output
reversed
Reverses the order of the loop. Note that this flag’s spelling is different from the filter reverse
.
Input
Output
forloop (object)
Information about a parent for
loop.
Use the forloop
object
forloop
objectInput
Output
forloop (properties)
Property | Description | Returns |
---|---|---|
| The total number of iterations in the loop. |
|
| The parent |
|
| The 1-based index of the current iteration. |
|
| The 0-based index of the current iteration. |
|
| The 1-based index of the current iteration, in reverse order. |
|
| The 0-based index of the current iteration, in reverse order. |
|
| Returns |
|
| Returns |
|
cycle
Loops through a group of strings and prints them in the order that they were passed as arguments. Each time cycle
is called, the next string argument is printed.
cycle
must be used within a for loop block.
Input
Output
Uses for cycle
include:
applying odd/even classes to rows in a table
applying a unique class to the last product thumbnail in a row
cycle (parameters)
cycle
accepts a “cycle group” parameter in cases where you need multiple cycle
blocks in one template. If no name is supplied for the cycle group, then it is assumed that multiple calls with the same parameters are one group.
Input
Output
tablerow
Generates an HTML table. Must be wrapped in opening <table>
and closing </table>
HTML tags. For a full list of attributes available within a tablerow
loop, refer to the tablerowloop
object.
Input
Output
tablerow (parameters)
cols
Defines how many columns the tables should have.
Input
Output
limit
Exits the tablerow
loop after a specific index.
offset
Starts the tablerow
loop after a specific index.
range
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
tablerowloop (object)
Information about a parent tablerow
loop.
tablerowloop (properties)
Property | Description | Returns |
---|---|---|
| The 1-based index of the current column. |
|
| The 0-based index of the current column. |
|
| Returns |
|
| Returns |
|
| Returns |
|
| The 1-based index of the current iteration. |
|
| The 0-based index of the current iteration. |
|
| Returns |
|
| The total number of iterations in the loop. |
|
| The 1-based index of the current iteration, in reverse order. |
|
| The 0-based index of the current iteration, in reverse order. |
|
| The 1-based index of current row. |
Last updated