【问题标题】:How to do a while loop in liquid/jekyll?如何在液体/jekyll中做一个while循环?
【发布时间】: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


【解决方案1】:

Liquid 中没有 while 循环。

你可以使用这样的 for 循环来满足你的要求吗

{% for counter in (0..9) %}
  <!-- the stuff to be done followed by an increase in the 'counter' variable -->
    {{ counter }}
{% endfor %}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-10
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多