How do I loop through a text metafield list?

How do I loop through a text metafield list?

Brandshark
Visitor
2 0 18

I have created a text metafield list called ingredients and I want to loop through it in liquid.

 

The problem is when I do  {{ product.metafields.info.ingredients }}, it gives me a result 

["Lorem Ipsum is simply dummy text of the printing.","Lorem Ipsum 2 is simply dummy text of the printing.","Lorem Ipsum 3 is simply dummy text of the printing.","Lorem Ipsum 4 is simply dummy text of the printing."]

 

But when I try to loop through it like this

{% for ingredient in product.metafields.info.ingredients %}
<li>{{ ingredient }}</li>
{% endfor %}

It doesn't output anything. Any idea what I am doing wrong? Please help.

Replies 6 (6)

Brandshark
Visitor
2 0 18

Solved it.

 

I was missing value in the for loop.

 

The correct syntax is

{% for ingredient in product.metafields.info.ingredients.value %}
<li>{{ ingredient }}</li>
{% endfor %}

filippodm
Visitor
1 0 3

YOU SAVED MY NIGHT!!! Thanks 🙂

HashtagDesign
Shopify Partner
8 0 2

Thank you! Burnt up an hour trying everything to get the output.

Was missing the .value also

julianabr
Shopify Partner
8 0 1

This has totally helped, but now i have another wrinkle. I want each item in the metafield array (which are separated by commas) to link to a search of that item. But what I'm getting is a link to both items. I don't think it is treating my metafield like an array. Is that something i needed to do when defining the metafield?

 

This is my code:

{% for movieactors in product.metafields.custom.movieactors.value %}
<a href="/search?q={{ movieactors }}" >{{ movieactors }}</a>
{% endfor %}

 

Thanks in advanced for any help you (or anyone else!) can provide.

_________________________________________________________________________________________
I'm an internet dinosaur who knows -just- enough to be dangerous.
ylmzcanpolat
Shopify Partner
1 0 0

Thanksss 🤙

sahilsince2000
Visitor
1 0 0

<img src="d">