【发布时间】:2016-09-17 20:17:33
【问题描述】:
我找不到关于 Liquid/jekyll 是否可以处理 while 循环的任何信息。所以要么没有人问过这个问题,要么谷歌不是很有帮助。这不是可以做到的吗?我基本上希望能够做这样的事情:
<!-- 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 %}
【问题讨论】:
-
如果你试图模拟
while,它会一直重复执行直到满足条件,尝试使用for i in (1..999)(或一个足够大的数字以覆盖最大可能的执行次数)然后使用if ... break ... endif在满足条件后退出循环。诚然,它不会永远执行,但它是最接近while的近似值。注意:这个技巧只有在你还没有迭代给定数组时才需要。
标签: while-loop jekyll liquid