shopify

I can't get an array in the for loop in Shopify


I'm using metaobjects in collections, in which I specify values.

This is how I can get the values as an array:

{{ collection.metafields.custom.filters.value.options }}

and I get this:

["option1","option2","option3"]

But when I try to get it in the for loop, I get nothing. I'm doing this:

{% for item in collection.metafields.custom.filters.value.options %}
   {{ item }}
{% endfor %}

I can't understand why this doesn't output anything as I use an array to get in a loop.

What is the problem here?


Solution

  • I was almost close to the right solution.

    I just need to add a second property value at the end of the metafield call. Like that:

    collection.metafields.custom.filters.value.options.value
    

    With the for loop it looks like this:

    {% for item in collection.metafields.custom.filters.value.options.value %}
       {{ item }}
    {% endfor %}