Reputation: 1005
I'm trying to set up a simple way to increment within for
loops in my themes and can't figure out how to get it to work. I'm familiar with two ways to increment:
{% assign variable = 0 %}
{% for .....
{% assign variable = variable | plus: 1 %}
.... endfor %}
and
{% assign variable = 0 %}
{% increment variable %}
However neither of these work. Update: Currently the following block of code will output "0" when it should be "1"
{% assign variable = 0 %}
{% assign variable = variable | plus: 1 %}
{{ variable }}
What am I doing wrong?
Upvotes: 2
Views: 12606
Reputation: 15402
What you are doing with the assign should work however there is an easier way:
{{forloop.index0}}
See the docs for the loop object
Upvotes: 3