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 there,
thanks for tip, but this one is not working either. No one any idea? 😞
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
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024