I’m creating a custom Shopify section to display product specifications using a metafield. My metafield named specs is set as an entry list, with each entry containing arrays for label and description. I want to loop through these arrays and render each label-description pair in a list or table format.
Here’s my current Liquid code:
{% assign specs_list = product.metafields.custom.specs.value %}
<ul>
{% for spec in specs_list %}
<li>
<span>{{ spec.label }}</span>
</li>
<li>
<span>{{ spec.description }}</span>
</li>
{% endfor %}
</ul>
Result:
["Label 1","Label 2","Label 3","Label 4","Label 5"]
["Valeur 1","Valeur 2","Valeur 3","Valeur 4","Valeur 5"]
However, spec.label and spec.description aren’t displaying the way I need, likely due to being detected as arrays within each entry.
Attempts so far: Despite trying various approaches to iterate through the arrays using nested loops, the current code version is the only one that works.
Expected Output: I want to display each label-description pair like this:
Label 1 | Value 1
Label 2 | Value 2
Label 3 | Value 3
2
Answers
I think this will work:
However just wrote this in vsCode, I haven’t tested it out.
Let me know if it works or not.
As your elems content in the list is formatted as an array you may outpout values as it: