Iteration tags run blocks of code repeatedly.
Repeatedly executes a block of code. For a full list of attributes available within a for loop, see forloop (object).
hat shirt pants
Causes the loop to stop iterating when it encounters the break tag.
1 2 3
Causes the loop to skip the current iteration when it encounters the continue tag.
1 2 3 5
Limits the loop to the specified number of iterations.
Begins the loop at the specified index.
3 4 5 6
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
3 4 5 1 2 3 4
Reverses the order of the loop. Note that the flag’s spelling is different to the filter reverse.
6 5 4 3 2 1
Loops through a group of strings and outputs them in the order that they were passed as parameters. Each time cycle is called, the next string that was passed as a parameter is output.
cycle must be used within a for loop block.
one two three one
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 accepts a parameter called cycle group 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.