Skip to content

for

Repeats a block for each item.

Inside the loop, forloop gives the position. limit and offset take part of the array, reversed walks it backwards, and else renders when the array is empty. Loops stop after 10,000 iterations per render.

{% for item in array limit: 4 offset: 0 reversed %}…{% else %}…{% endfor %}
Name Type Description
limit number Most items to loop over.
offset number Items to skip first.
reversed flag Loop from the end.
Liquid
{% for variant in product.variants %}{{ forloop.index }}. {{ variant.title }}{% unless forloop.last %}, {% endunless %}{% endfor %}
Output
1. S / Sand, 2. M / Sand, 3. L / Sand
Liquid
{% for i in (1..3) %}{{ i }}{% endfor %} {% for item in cart.discounts %}{{ item }}{% else %}No discounts{% endfor %}
Output
123

Shopify: Same as Shopify.

Since theme platform 1.0.

Was this page helpful?