Liquid, JavaScript, themes, sales channels
{% 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>
User | RANK |
---|---|
25 | |
24 | |
8 | |
7 | |
6 |
Explore the 30-30-30 rule, a dynamic social media strategy for new businesses. Learn how t...
By Trevor Sep 20, 2023Discover how to leverage the often overlooked footer of your ecommerce site to gain custom...
By Skye Sep 15, 2023In this blog, we’ll be shining a light on Shopify Partners, Experts, and Affiliates. Who a...
By Imogen Sep 13, 2023