Iteration

Iteration tags run blocks of code repeatedly.

for

Repeatedly executes a block of code. For a full list of attributes available within a for loop, see forloop (object).

Input

Output

hat shirt pants

break

Causes the loop to stop iterating when it encounters the break tag.

Input

Output

1 2 3

continue

Causes the loop to skip the current iteration when it encounters the continue tag.

Input

Output

1 2 3   5

for (parameters)

limit

Limits the loop to the specified number of iterations.

Input

Output

1 2

offset

Begins the loop at the specified index.

Input

Output

3 4 5 6

range

Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.

Input

Output

3 4 5
1 2 3 4

reversed

Reverses the order of the loop. Note that the flag’s spelling is different to the filter reverse.

Input

Output

6 5 4 3 2 1

cycle

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.

Input

Output

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 (parameters)

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.

Got an issue? Or want to submit feedback?
Submit your feedback

Our new Feedback and Issue Tracker is built on GitHub Issues. Just leave your comment below and you can track our team resolve it, or browse issues others have already submitted.

Read how to use the Feedback and Issue Tracker