- 27 Jun 2021
- 2 Minutes to read
Iteration
- Updated on 27 Jun 2021
- 2 Minutes to read
for
Repeatedly executes a block of code. For a full list of attributes available within a for
loop, see forloop (object).
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
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
Input
Output
3 4 5
Reverses the order of the loop. Note that this flag’s spelling is different from the filter reverse
.
Input
{% assign array = (1..6) %}
Output
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.
Input
Output
tablerow (parameters)
Defines how many columns the tables should have.
Input
Output
Defines a range of numbers to loop through. The range can be defined by both literal and variable numbers.
forloop.first
Returns true
if it's the first iteration of the for loop. Returns false
if it is not the first iteration.
Input
Output
forloop.index
Returns the current index of the for loop, starting at 1.
Input
Output
forloop.index0
Returns the current index of the for loop, starting at 0.
Input
Output
forloop.last
Returns true
if it's the last iteration of the for loop. Returns false
if it is not the last iteration.
Input
Output
forloop.length
Returns the number of iterations of the loop.
Input
Output
forloop.rindex
Returns forloop.index in reverse order.
Input
Output
forloop.rindex0
Returns forloop.index0 in reverse order.
Input
Output