Access to metaobject data or format it

Access to metaobject data or format it

Delio
Shopify Partner
18 0 1

Hello,

 

I have a metaobject structure that can be assigned to either a product or a collection.

By inserting this code (which is the reference for metafield)

 

{{ product.metafields.custom.keylabels_desc.value | json}} 


I receive this output

 

{"collections":["gid:\/\/shopify\/Collection\/325100830915"],"keylabels":["ferro da stiro","lavatrice","asciugatrice"],"name":"key01","product":["gid:\/\/shopify\/Product\/7726321336515","gid:\/\/shopify\/Product\/7726324515011"],"text":{"type":"root","children":[{"type":"paragraph","children":[{"type":"text","value":"questa è la key 01"}]}]}}

I would like to either be able to correctly format the output or extract the handle of the metaobject that is being referenced. Is this possible?

Replies 3 (3)

joeybab3
Shopify Partner
126 16 32

 

I'm assuming .handle doesn't work?

{{ product.metafields.custom.keylabels_desc.value.handle }}  

 It's hard to say for sure without knowing the structure of your metaobject or at least in your example which the handle is

Delio
Shopify Partner
18 0 1

Hello,

no it doesn't work because that is the metafield through which the metaobject is referenced. The metaobject is key_label and inside it has various fields, such as key_label.keylabels

 

Delio_1-1716449967435.png

 

Delio_0-1716449890364.png

 

felipelf00
Shopify Partner
3 0 0

I have a similar issue. I was able to display the values using a | json filter, but In my case the metafield is set as "list of entries" and I can't find a way ti access each entry.

 

I just posted mine here: https://community.shopify.com/c/metafields-and-custom-data/acessing-metaobject-data-from-product-met...