We created custom meta object and definition using Graphql. Everything is working as expected via Graghql, i.e. create, update, delete meta object works fine. But meta objects(created via Graphql) are not available to storefront via theme liquid file. We would like to display meta object data info within shop via liquid.
Example,
Meta Object Type: product_custom
Handle: product-custom-ydhnjq17
So within theme, meta object should be available. We added below code within liquid file to display field from that meta object as shown below for example:
{{ shop.metaobjects['product_custom']['product-custom-ydhnjq17'].product_custom_title.value }}
But we are not getting meta objects value within liquid objects.
We also added similar liquid within theme app extension file within app
extensions/product-custom/blocks/app-block.liquid.
But via theme app extension, same thing; we are also not getting metaobject value in app extension (both in direct liquid file and app extension).
Can someone help us on this?
We are following
https://shopify.dev/apps/custom-data/metaobjects/manage-metaobjects
and
https://shopify.dev/api/liquid/objects/metaobject
1 Like
@PlusApps Any luck with this?
Not sure if this helps but i got this to give me the liquid collection object for this meta object.
Hello Khalid_Nazmus_S,
I just ran into the same problem you did and let’s just say the documentation is not very helpful. It will improve, but here is how I found a solution for my issue (might be a bit different from your situation). In my case, I wanted to build a section in custom liquid to display logos and links to collaborators in a product.
Step 1 : Create a new product page template with a very specific name (so you can test things in it and find it later).
Step 2 : Pick a section that is going to fit the type of dynamic content you want to display. Mine was single line text so I picked a text section.
Step 3 : Add the section and connect your metaobject content via dynamic content.
Step 4 : Save
Step 5 : Find your new product page template JSON file in the “Edit code” of the theme
Step 6 : Look for your metaobject (whatever you used in the definition)
Step 7 : Copy the code structure and use it in custom liquid.
For exemple, mine was {{ shop.metaobjects.collaboration.collaboration_logo_1.value }} based on the documentation and wasn’t working at all. It ended up being {{ product.metafields.custom.collaboration.value.collaboration_logo_1.value }} in the JSON and is now working. I’d never have thought of that structure myself.
Hope it helps!
Francis
{% for metaobject in shop.metaobjects.product_custom**.values** %}
{{ metaobject.title }}
{% endfor %}
values needs to be added at the end to loop on existing metaojects of type product_custom.