Get next and previous elements out of an array in liquid

后端 未结 5 1662
独厮守ぢ
独厮守ぢ 2021-02-03 11:48

Short version:

I want to add 1 to a number in a liquid template and use the result as an array index.

{% capture plus_one %}{{ 0 | plus: 1 }}{% endcaptur         


        
5条回答
  •  旧时难觅i
    2021-02-03 12:15

    assign preserves the number:

    {% for item in items %}
        {% assign next_i = forloop.index0 | plus: 1 %}
        {% assign prev_i = forloop.index0 | minus: 1 %}
        {{ items[next_i] }}
        {{ items[prev_i] }}
    {% endfor %}
    

提交回复
热议问题