Iteration Tags

In this article:


for

Repeatedly executes a block of code.

<p>Downloads:</p> <ul> {% for download in post.downloads %} <li><a href="{{ download.url }}">{{ download.display_name }}</li> {% endfor %} </ul>

break

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

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

continue

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

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

limit

limit is a parameter for for. Exits the for loop at a specific index.

<p>Downloads:</p> <ul> {% for download in post.downloads limit: 2 %} <li><a href="{{ download.url }}">{{ download.display_name }}</li> {% endfor %} </ul>

offset

offset is a parameter for for. Starts the for loop at a specific index.

<p>Downloads:</p> <ul> {% for download in post.downloads offset: 2 %} <li><a href="{{ download.url }}">{{ download.display_name }}</li> {% endfor %} </ul>

range

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

{% assign num = post.downloads.size %} {% for i in (1..num) %} {{ i }} {% endfor %}

reversed

reversed is a parameter for for. Reverses the order of the for loop.

<p>Downloads:</p> <ul> {% for download in post.downloads reversed %} <li><a href="{{ download.url }}">{{ download.display_name }}</li> {% endfor %} </ul>

Contact support or access our 24/7 Live Chat:

Contact Support Live Chat

Need Help? Live Chat with Us.