Get next and previous elements out of an array in liquid

后端 未结 5 1646
独厮守ぢ
独厮守ぢ 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条回答
  •  粉色の甜心
    2021-02-03 12:10

    I was having a similar problem, using the answers above I got the following working on my site. Might be of help to someone else.

    {% for num in (0..site.categories.work.size) %}
        {% assign page2 = site.categories.work[num] %}
        {% if page2.title == page.title and page2.date == page.date %}
            {% assign next_i = forloop.index0 | plus: 1 %}
            {% assign prev_i = forloop.index0 | minus: 2 %}
    
            {% if next_i == site.categories.work.size %}
                {% assign next_i = 1 %}
            {% endif %}
        {% endif %}
    {% endfor %}
    
    
    

提交回复
热议问题