I know I can iterate over arrays in liquid template with this code:
{% for item in myarray %}
<p>{{ item.label }}</p>
But how can I get the index of my item within the array?
According to the "Liquid for Designers" section on liquid's github...
forloop.length # => length of the entire for loop
forloop.index # => index of the current iteration
forloop.index0 # => index of the current iteration (zero based)
forloop.rindex # => how many items are still left?
forloop.rindex0 # => how many items are still left? (zero based)
forloop.first # => is this the first iteration?
forloop.last # => is this the last iteration?
All of these are helper variables for for
loops. You will find these two most useful...
forloop.index # => index of the current iteration
forloop.index0 # => index of the current iteration (zero based)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With