Iteration (dealing with lists)
Last updated
Was this helpful?
Last updated
Was this helpful?
Looping over lists is a very frequent need and in this guide we'll go over the various ways you can do it.
Here are the essential aspects of iteration but you can learn more in .
Let's use the data we defined in :
We can loop over the lineItems
array to list our products using a for
loop. It will repeat the code for each item in the array:
The resulting HTML will look like this:
Inside a for
loop, you get access to a special object that stores the current state of the loop. It can be useful to build special cases for the first or last iteration, for instance.
We're formatting the monetary values using the with_delimiter
filter here. You can learn more in our documentation about and the .
You can learn more about iterating over lists in , including things like limit
, offset
, etc.
The filter
The filter
Discover the complete range of possibilities of forloop
in , including things like index
, index0
or length
.