Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
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
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?
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 %}
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.
Yes, you have to make your hands dirty on this. Since, metaobject are not being called using dynamic source