Looping and Iteration

Modified on Sun, 9 Mar at 4:22 PM

You can iterate through HTML or liquid code by using the For loop. Loops are especially useful for things like running through and displaying all the solutions under a specific folder.


Syntax:

 

{% for item in array %}<!-- Do something with each item -->{% endfor %}


You can also limit the number of iterations by using the limit parameter. 

{% for folder in category.folders limit: 6 %}

<!-- Just show the first 6 folders -->

{% endfor %}


There are times when you want to start looping from the second, fifth or the n’th item in your list. You can do this using the offset parameter.


{% for forum in portal.forums offset: 2 %}

<!-- Start the loop from the 3rd forum -->

{% endfor %}



Next: Assigning Variables 

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article