Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Unable to access ProductImage Metafield with Liquid

Unable to access ProductImage Metafield with Liquid

Maacck
Shopify Partner
22 1 4

Hi Guys,

 

As shopify does not support China CDN anymore, we plan to build our own cdn for china customer as store the new image url in ProductImage metafield. However, when we tried to access the metafield in Liquid seems like it does not work. Is it possibly that Liquid does not have access to Product Image metafield? Because I am 100% sure that ProductImage has metafield and we have successfully added it.

Replies 2 (2)

MetafieldsGuru
Shopify Partner
160 32 103

Hi @Maacck ,

 

The thing is that the payload returned for a file/image metafield is a generic file object .

You can display an image by combining the Liquid code, an image_url filter and proper HTML <img> tag.

Instead of a single line of code like this:
{{ product.metafields.namespace.key.value }}
You may want to use a snippet like this:
{% assign image_url = product.metafields.namespace.key %}
{% if image_url != blank %} 
 <img src="{{ image_url.value | image_url }}">
{% endif %}
Check out Metafields Guru, the #1 ranked metafields app.

Bulk editor | Data import/export | Metafield sets | Browser extension
Maacck
Shopify Partner
22 1 4

I was try to access the ProductImage's metafield instead of Product itself, and seems like is does not work.