简体   繁体   中英

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 %}

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 %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM