Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incrementing variables in liquid without outputting them

Tags:

shopify

liquid

I am doing a for loop in shopify, I need to increment a variable.

However, when I do

{% increment variable %}

besides incrementing it, it shows the output on the screen!

I can't believe it. Is there a way to avoid this?

Thank you

like image 707
user3808307 Avatar asked Mar 20 '16 06:03

user3808307


1 Answers

If you are using a different logic for incrementing the value than forloop.index, you can use the plus filter to increment the variable:

{% assign variable = 0 %}
{% for … %}
  {% assign variable = variable | plus: 1 %}
{% endfor %}

I can also recommend that you have a look at the cheat sheet for Shopify.

like image 96
HymnZzy Avatar answered Sep 19 '22 23:09

HymnZzy