View Source Liquex.Tag.ForTag (liquex v0.13.0)

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

Input

{% for product in collection.products %}
  {{ product.title }}
{% endfor %}

Output

hat shirt pants

else

Specifies a fallback case for a for loop which will run if the loop has zero length.

Input

{% for product in collection.products %}
  {{ product.title }}
{% else %}
  The collection is empty.
{% endfor %}

Output

The collection is empty.

break

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

Input

{% for i in (1..5) %}
  {% if i == 4 %}
    {% break %}
  {% else %}
    {{ i }}
  {% endif %}
{% endfor %}

Output

1 2 3

continue

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

Input

{% for i in (1..5) %}
  {% if i == 4 %}
    {% continue %}
  {% else %}
    {{ i }}
  {% endif %}
{% endfor %}

Output

1 2 3   5

for (parameters)

limit

Limits the loop to the specified number of iterations.

Input

<!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit:2 %}
  {{ item }}
{% endfor %}

Output

1 2

offset

Begins the loop at the specified index.

Input

<!-- if array = [1,2,3,4,5,6] -->
{% for item in array offset:2 %}
  {{ item }}
{% endfor %}

Output

3 4 5 6

To start a loop from where the last loop using the same iterator left off, pass the special word continue.

Input

<!-- if array = [1,2,3,4,5,6] -->
{% for item in array limit: 3 %}
  {{ item }}
{% endfor %}
{% for item in array limit: 3 offset: continue %}
  {{ item }}
{% endfor %}

Output

1 2 3
4 5 6

range

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

Input

{% for i in (3..5) %}
  {{ i }}
{% endfor %}

{% assign num = 4 %}
{% assign range = (1..num) %}
{% for i in range %}
  {{ i }}
{% endfor %}

Output

3 4 5
1 2 3 4

reversed

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

Input

<!-- if array = [1,2,3,4,5,6] -->
{% for item in array reversed %}
  {{ item }}
{% endfor %}

Output

6 5 4 3 2 1

Summary

Functions

Callback implementation for Liquex.Tag.parse/0.

Callback implementation for Liquex.Tag.parse_liquid_tag/0.

Link to this function

render(content, context)

View Source

Callback implementation for Liquex.Tag.render/2.

Link to this function

render_collection(results, identifier, contents, contents, context)

View Source