Ad

Looping Through Collections Doesn't Work

- 1 answer

I'm making a page where I need to compare an input ( in a form ) to the titles of my existing collections.

Right now I'm trying to loop like this:

div class="test">
    {{% for collection in collections %}}
        {{collection.title}}
    {{% endfor %}}
  </div>

I've seen this code in another snippet ('collection-listing.liquid') so I assumet it might be correct.

Could anyone tell me why it's not working? I'm new at this so I still don't fully understand Shopify.

Ad

Answer

From what I can tell from your snippet, try to fix the malformed HTML tag first.

Next, there is an error in the for loop. Instead of

{{% for .... %}} ... {{% endfor %}}

it's

{% for ... %} ... {% endfor %}

   <div class="test">
        {% for collection in collections %}
            {{collection.title}}
        {% endfor %}
   </div>
Ad
source: stackoverflow.com
Ad