【发布时间】:2018-06-11 07:11:44
【问题描述】:
我正在努力弄清楚如何在 Liquid/Jekyll 的 for 循环中增加索引变量。目前,我有一些类似
的东西{% for i in (0..num_posts) %}
{% if i < some_value %}
do_thing
{% else %}
{% endif %}
{% assign i = i|plus:1 %}
{% if i<some_value %}
do_another_thing
{% else %}
{% endif %}
{% endfor %}
问题是,它没有增加 i,而是将 i 保留为相同的值。
我尝试过的事情:
- 使用
{% assign i = i|plus:1 %}。 - 使用
{% increment i %}。 -
使用
{% assign j = i|plus:1 %} {% assign i = j %}
我也不能使用offset 命令,因为代码并不总是只检查循环中的 2 个 if 语句。
有什么想法吗?
【问题讨论】: