Access metaobject child assigned to metafield

Solved

Access metaobject child assigned to metafield

LuxStore
Shopify Partner
6 0 0

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. 

Accepted Solution (1)
Sonya_2025
Shopify Partner
246 32 46

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 %}

 

Please let me know if it works by giving it a Like or marking it as a solution!
Feel free to reach out. EMAIL ME  
Motivate me by  PAY ME

View solution in original post

Replies 9 (9)

Sonya_2025
Shopify Partner
246 32 46

Hi @LuxStor

Try to using

<img src="{{product.metafields.custom.productcare.product_care_img}}">

 

instead of your code.

 

Hope this helps.

Please let me know if it works by giving it a Like or marking it as a solution!
Feel free to reach out. EMAIL ME  
Motivate me by  PAY ME
LuxStore
Shopify Partner
6 0 0

Hi there, 

 

thanks for tip,  but this one is not working either. No one any idea? 😞

 

 

Sonya_2025
Shopify Partner
246 32 46

Hey

This one should work. Pls have a try 

{{ product.metafields.custom.productcare.value.product_care_img.value | image_url: width: 200 | image_tag }}
Please let me know if it works by giving it a Like or marking it as a solution!
Feel free to reach out. EMAIL ME  
Motivate me by  PAY ME
LuxStore
Shopify Partner
6 0 0

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. 

Sonya_2025
Shopify Partner
246 32 46

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 -%}

 

  

Please let me know if it works by giving it a Like or marking it as a solution!
Feel free to reach out. EMAIL ME  
Motivate me by  PAY ME
LuxStore
Shopify Partner
6 0 0

Sure, please find the definition following: 

Screenshot 2024-05-22 150858.pngScreenshot 2024-05-22 151132.pngScreenshot 2024-05-22 151150.png

Sonya_2025
Shopify Partner
246 32 46

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 %}

 

Please let me know if it works by giving it a Like or marking it as a solution!
Feel free to reach out. EMAIL ME  
Motivate me by  PAY ME
LuxStore
Shopify Partner
6 0 0

Hi Sonya, 

 

that's it. It is working with that one, big thanks from my side!!

 

Best Regards

 

Sonya_2025
Shopify Partner
246 32 46

It's glad to hear that. You are welcome.

Please let me know if it works by giving it a Like or marking it as a solution!
Feel free to reach out. EMAIL ME  
Motivate me by  PAY ME