I'm trying to do something very simple. I wrote:
{% for product in collection.products %}
{{ if forloop.index = 1 }}
Hello World!
{{ endif }}
{% endfor %}
Problem: "Hello World!" appears in every iteration. What is wrong here?
Looks like in each round of the loop, you're overwriting the index to always be equal to 1. Try
{% if forloop.index == 1 %}
instead.
So here again the right version, answering my own question... ;)
{% for product in collection.products %}
{% if forloop.index == 1 %}
Hello World!
{% endif %}
{% endfor %}
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