0
votes

i am trying to get every block that has an even position in shopify liquid inside a forloop :

{% for block in section.blocks %}
      {% if forloop.index | modulo : 2 == 0%}
        //some code
      {%endif%}
{% endfor %}

but shopify returns me this error:

Expected end_of_string but found pipe in "forloop.index | modulo : 2 == 0"

Can somone help me solve this? Thanks in advance :D

1
Possibly a duplicate of this question? stackoverflow.com/questions/65133100/…Dave B

1 Answers

2
votes

You need to split calculations from logic in liquid.

{% assign num = forloop.index | modulo: 2 %}
{% if num == 0 %}
    // code
{% endif %}

So you must save the module calculation as variable and check it after that, you can't do the check and calculation at the same time.