Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
{% for metafield in product.metafields.namespace %}
<li>{{ metafield }} </li>
{% endfor %}
outputs
<li>namespacekey</li>
which is great, but how do I split namespace and key?
The direct access is great and all but it gets pretty cumbersome:
{% if product.metafields.knife.blade_engraving.value != 'blank' %}
<li>
Blade engraving: {{ product.metafields.knife.blade_engraving.value | metafield_tag }}
</li>
{% endif %}
repeat for all metafields (in my case 20).
It'd be more elegant if we could loop through this.
Is there a way to grab the Name and Description from the Shopify backend?
Solved! Go to the solution
This is an accepted solution.
Just checked it and your description is true... It's counterintuitive. The mechanism they provide is .first and .last properties I works on the json metafield type and others as well:
ex>
Hi @SpotterJ,
You can't loop over a namespace to get each individual metafield. Refer https://shopify.dev/api/liquid/objects/metafield#direct-access
So you can't "for" it, you can just get out each metafield.
Hope it helps!
That's not strictly true. With my example above I do get a list of all the metafields namespaces and their values, however there's no space between the two.
Hi @SpotterJ,
Yes, I totally know this, you will be returned a text including the name and value.
But currently, there is no way to separate it. You can refer to shopify's instructions.
If it helped you solve your issue, please mark it as a solution. Thank you and good luck.
I ended up with direct access, couldn't find a way to split the two.
This is an accepted solution.
Just checked it and your description is true... It's counterintuitive. The mechanism they provide is .first and .last properties I works on the json metafield type and others as well:
ex>