Get next and previous elements out of an array in liquid

后端 未结 5 1642
独厮守ぢ
独厮守ぢ 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:23

    You can access the next / previous post via page.next or page.previous as described in the jekyll wiki.

    When you want it to be in the same category, you have to assign it to a temp variable iterate that step until you find a matching post (a post in the same category).

    You can not use your plus_one variable because of the way liquid works - it's just a string. Using math in liquid is quite complicated, I almost got a headache when I implemented my weighted tag cloud in liquid.

提交回复
热议问题