Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a while loop in liquid/jekyll?

I can't find any info on whether liquid/jekyll can handle while loops. So either no one has asked this question, or Google isn't being very helpful. Is this not something that can be done? I'd essentially like to be able to do something like this:

<!-- creates the 'counter' variable-->
{% assign counter = 0 %}
<!-- while 'counter' is less than 10, do some stuff -->
{% while counter < 10 %}
  <!-- the stuff to be done followed by an increase in the 'counter' variable -->
  {% assign counter = counter | plus: 1 %}
<!-- the completion of the loop -->
{% endwhile %}
like image 244
John R Perry Avatar asked Sep 17 '16 20:09

John R Perry


1 Answers

No while loops in Liquid.

Can you use a for loop like this for your requirement

{% for counter in (0..9) %}
  <!-- the stuff to be done followed by an increase in the 'counter' variable -->
    {{ counter }}
{% endfor %}
like image 146
visamba Avatar answered Oct 23 '22 14:10

visamba