Personalized checkout and custom promotions with Shopify Scripts
Hi there,
I'm struggling with some (probably) minor issue, and this forum was quite helpfull in the past.
We have the following situation:
I have a Metaobject Definition called "ProductCare". This definition is holding 2 fields
1: ProductCareImg (File)
2: ProductCareDescription (Single line text)
Then I have a Product metafield called "ProductCare", which can carry a variable number of MetaObject Definition "ProductCare" (List of entries on Metaobject). The namespace + key is: "custom.productcare"
Now I want to access, the images on my product page, which I'm struggling with. I have done it for the texts with this line of liquid:
{{ product.metafields.custom.productcare | metafield_tag: field: 'product_care_description' }}
For the images however, I am not able to manage this to work. Analog to the above, this one is not working
{{ product.metafields.custom.productcare | img_tag: 'product_care_img', '', 'thumb' }}
It just shows a "No image" sign, as if this was empty.
Does anyone have an idea, what I did wrong?
Best regards,
LuxStore
EDIT: And yes, before you ask, the field is populated with data, the text is showing.
Solved! Go to the solution
This is an accepted solution.
ok, I see. Your product metafield is a list. So you need add a for tag like this
{%- for productcare in product.metafields.custom.productcare.value -%}
{{ productcare.product_care_img.value | image_url: width: 100 | image_tag }}
{% endfor %}
Hi @LuxStor
Try to using
<img src="{{product.metafields.custom.productcare.product_care_img}}">
instead of your code.
Hope this helps.
Hi there,
thanks for tip, but this one is not working either. No one any idea? 😞
Hey
This one should work. Pls have a try
{{ product.metafields.custom.productcare.value.product_care_img.value | image_url: width: 200 | image_tag }}
Hi Sonya,
thanks, I think we are a step closer to the solution. However I'm getting the following instead of an image:
Liquid error (line 1): invalid url input
Putting
product.metafields.custom.productcare.value.product_care_img.value
Into an <img src="***"> tag, does not work either, it's again the "No image" wildcard popping up.
Can you share the metaobject definition in shopify admin?
May be you should add if condition to make sure the product_care_img have a value.
{%- if product.metafields.custom.productcare.value.product_care_img.value -%}
{{ product.metafields.custom.productcare.value.product_care_img.value | image_url: width: 200 | image_tag }}
{%- endif -%}
Sure, please find the definition following:
This is an accepted solution.
ok, I see. Your product metafield is a list. So you need add a for tag like this
{%- for productcare in product.metafields.custom.productcare.value -%}
{{ productcare.product_care_img.value | image_url: width: 100 | image_tag }}
{% endfor %}
Hi Sonya,
that's it. It is working with that one, big thanks from my side!!
Best Regards
It's glad to hear that. You are welcome.
2m ago Learn the essential skills to navigate the Shopify admin with confidence. T...
By Shopify Feb 12, 2025Learn how to expand your operations internationally with Shopify Academy’s learning path...
By Shopify Feb 4, 2025Hey Community, happy February! Looking back to January, we kicked off the year with 8....
By JasonH Feb 3, 2025