How to render out a metaobject image

How to render out a metaobject image

mns-burg
Tourist
13 0 0

How do I render out a Meta object string and image in a Custom Liquid code section on my product page?

I'm trying to make a "brand badge" for every product, to display what brand they are connected to but can not wrap my head around this.

Do you call it through metafield?
{{ product.metafields.custom.brandbadge }}

Or do you call it through metaobjects?
{{ shop.metaobjects.brand_object.name }}

And do you render out the content?

I have been looking at https://shopify.dev/docs/api/liquid/objects/metaobject but can not seam to understand it.

Replies 5 (5)

webwondersco
Shopify Partner
1132 167 165

@mns-burg Hope you are doing well.

 

Metaobject is a global object so you have to use it like below:

 

{{ metaobject.title.value }}

Web Wonders | Shopify Partner | Connect here!
- Question answered? Mark as Accepted Solution, reply helpful? Click Like
- Hire me, if you want to design, re-design, develop a store, or make changes to the pre-built store.
- a small Coffee Tip would be greatly appreciated. :)..! Instagram
mns-burg
Tourist
13 0 0

Is that also the case if I want to show a metaobject on my product page using the "Custom Liquid" section?
I can not seam to get it to render/output anything.

webwondersco
Shopify Partner
1132 167 165

@mns-burg yes you can. but you have to use your handle of metaobject to access in product page

Web Wonders | Shopify Partner | Connect here!
- Question answered? Mark as Accepted Solution, reply helpful? Click Like
- Hire me, if you want to design, re-design, develop a store, or make changes to the pre-built store.
- a small Coffee Tip would be greatly appreciated. :)..! Instagram

websensepro
Shopify Partner
1059 150 159

Hello @mns-burg,

Certainly! To display a brand badge using metafields, use the following Liquid code:

<div class="brand-badge">{{ product.metafields.custom.brandbadge }}</div>

If you’re using metaobjects, replace the metafield reference with the appropriate metaobject field:

<div class="brand-badge">{{ shop.metaobjects['brand_object']['name'] }}</div>

Remember to adjust the class names and styling according to your theme.

Thanks!

Need a Shopify developer?
Hire us at WebSensePro
For Shopify Design Changes | Shopify Custom Coding | Custom Modifications
Subscribe to our youtube channel or buy us a Cofee here
mns-burg
Tourist
13 0 0

How will I go around targeting the metaobject, that have been chosen in the individual products metafield.
I seam to get no output or a the text "MetaobjectDrop".