Shop-wide Metafield or Metaobject

MsMinis
Tourist
11 0 7

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
3805 713 1128

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 %}

 

 

 

 

Volunteering to assist you!  Likes and Accept as Solution  is highly appreciated.✌
Coffee fuels my dedication. If helpful, a small Coffee Tip would be greatly appreciated.
Need EXPERIENCED Shopify developer without breaking the bank?
Hire us at Made4Uo.com for quick replies.
Stay in control and maintain your security by avoiding unnecessary store access!
MsMinis
Tourist
11 0 7

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
3805 713 1128

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

Volunteering to assist you!  Likes and Accept as Solution  is highly appreciated.✌
Coffee fuels my dedication. If helpful, a small Coffee Tip would be greatly appreciated.
Need EXPERIENCED Shopify developer without breaking the bank?
Hire us at Made4Uo.com for quick replies.
Stay in control and maintain your security by avoiding unnecessary store access!