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

How can I create a universal Metaobject for all product pages?

How can I create a universal Metaobject for all product pages?

MsMinis
Excursionist
13 0 12

I have been doing a lot with Metafields and Metaobjects lately, they're great. Now, I want to create a Metaobject with some 'generic information' like a Title and Description and use these properties to fill a certain Tab on my product pages.

(Keep in mind that I have multiple product-page templates for different types of products.)

This way I would have the actual text and translations in one spot. I don't have to duplicate any text in multiple templates, multiple places that have to be translated and I also don't have to worry about text running out of sync between the different templates.

Now, I thought this should have been possible with Metafields / Metaobjects using some kind of 'Shop'-Metafield that would hold a Metaobject. So a Metaobject accessibel from everywhere. This, however, does not seem to exist.

The alternative would be to create Metaobject and create a 'Product'-Metafield that would hold that Metaobject but then I would have to assign the Metaobject to every single product in my store. Doable, yes. Good solution, not really.

So, are there any other options for me?

Replies 3 (3)

made4Uo
Shopify Partner
3877 719 1237

No. You do not need to assign the metaobject to a product, or any. It is a global variable. It is key value pair, an object. You call them by its key.

I usually try to use console.log and see what values are available for me. 

 

 

<script>
console.log({{shop.metaobjects['sample'].values }})
</script>

 

 

 

 

You can refer to the code below to call the array of values in your theme

 

 

{% assign samples = shop.metaobjects['sample'].values %}

{% for sample in samples %}
{% assign sample_name = sample.name %}
{% assign sample_link = sample.link %}
{% endfor %}

 

 

 

 

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free
MsMinis
Excursionist
13 0 12

Thanks. That's something to consider.

 

I forgot to mention that the place where I want to use the title and description is a section that was included with the theme.

 

One of those fields in the customizer where you can select a dynamic source.

 

I'll probably have to edit the section so it accepts those global metaobjects as input.

made4Uo
Shopify Partner
3877 719 1237

Yes, you have to make your hands dirty on this. Since, metaobject are not being called using dynamic source

If this fixed your issue Likes and Accept as Solution is highly appreciated. Coffee tips fuels my dedication.
Get EXPERIENCED Shopify developers at affordable rates—visit Made4Uo.com for quick quote!
Do not lost your Shopify store! Get FREE trial with ✔️ Rewind Backup: Automatic, reliable, stress-free