Help using nested metaobjects and liquid code

Solved

Help using nested metaobjects and liquid code

weaverslodge
New Member
4 0 0

Hi Guys, 

 

Please forgive this - I'm sure it will be an easy answer and I'm probably just an idiot but I'm new to all this stuff. 

 

So I am putting together a site selling pens - all of the pen types that I'm selling have their fields in a metaobject, so they have 

 

Name      

Type of Pen        

Image      

Description    

Default Case - Links to the Pen Cases metaobject

So what I want to do is - on the product page - display all the relevant details of the product but also the default case details. 

So I have a metafield called Pen Case which is linked to the Pen Cases metaobject which has the following fields in it 

 

Case Name 
Image

Description 

So on my product page I'l trying to add a bit of liquid code to display the Default case for that pen type - I'd like to add the image too but first things first. 

so my simplistic understanding of the liquid code would suggest I just need to add

 

{{ products.metafields.custom.pen_case.value }} but I figure this will just give me a pointed to another metaobject so I figure I need to go in further and have tried 

{{ products.metafields.custom.pen_case.case_name.value }}

 

It feels like I've tried every combination but I'm worried that I have a fundamental misunderstanding of how this data can be used. 

 

HELP !!! 😀

Accepted Solution (1)
Darshan17
Shopify Partner
26 2 4

This is an accepted solution.

Hi, 

can you please confirm ?
This is what you have expected ? 

Darshan17_0-1747047375235.png

Thanks ! 

If this fixed your issue, a Like and marking it as a Solution would mean a lot!
Shopify Developer | Helping eCommerce Stores Grow – cmsMinds (Shopify Partner)
Need help improving your Shopify store to stay ahead of market trends or need expert support?
 Connect with me at ujjawal@cmsminds.com

View solution in original post

Replies 8 (8)

Darshan17
Shopify Partner
26 2 4

Hi 

when you have a metaobject reference, you need to access its fields like this: 

{{ product.metafields.custom.pen_case.case_name }}

So on your product page, you should write:

{% if product.metafields.custom.pen_case %}
  <div class="pen-case-details">
    <h3>{{ product.metafields.custom.pen_case.case_name }}</h3>
    <p>{{ product.metafields.custom.pen_case.description }}</p>
    {% if product.metafields.custom.pen_case.image %}
      <img src="{{ product.metafields.custom.pen_case.image | image_url: width: 500 }}" alt="{{ product.metafields.custom.pen_case.case_name }}">
    {% endif %}
  </div>
{% endif %}

Let me know if this is not solving your problem. 

 

If this fixed your issue, a Like and marking it as a Solution would mean a lot!
Shopify Developer | Helping eCommerce Stores Grow – cmsMinds (Shopify Partner)
Need help improving your Shopify store to stay ahead of market trends or need expert support?
 Connect with me at ujjawal@cmsminds.com
weaverslodge
New Member
4 0 0

ok - tried that, no joy - I've checked that the names used are the ones I've said - I can't see a typo anywhere - I'm stumped as to how to debug it to be honest. Anything else that could be impacting it ? 

weaverslodge
New Member
4 0 0

Anyone got any further ideas - I haven't managed to spot what the problem is - Is there anything that I can upload to assist diagnosis?

Darshan17
Shopify Partner
26 2 4

You should try this 

{% assign pen_case = product.metafields.custom.pen_case.value %}

{% if pen_case %}
  <h3>{{ pen_case.case_name.value }}</h3>
  <p>{{ pen_case.description.value }}</p>
  <img src="{{ pen_case.image | image_url: width: 500 }}" alt="{{ pen_case.case_name.value }}">
{% endif %}


if this is not working then might be I need Collab access to check everything is set properly. 

If this fixed your issue, a Like and marking it as a Solution would mean a lot!
Shopify Developer | Helping eCommerce Stores Grow – cmsMinds (Shopify Partner)
Need help improving your Shopify store to stay ahead of market trends or need expert support?
 Connect with me at ujjawal@cmsminds.com
weaverslodge
New Member
4 0 0

Hi - no that didn't work - how do I sort out collab access ? 

Thanks for your assist 

Darshan17
Shopify Partner
26 2 4

I need your store url and collab access code. 

 

If this fixed your issue, a Like and marking it as a Solution would mean a lot!
Shopify Developer | Helping eCommerce Stores Grow – cmsMinds (Shopify Partner)
Need help improving your Shopify store to stay ahead of market trends or need expert support?
 Connect with me at ujjawal@cmsminds.com
Darshan17
Shopify Partner
26 2 4

Hi 

Here are the steps to provide the collaborator access code. 

Darshan17_0-1746792966235.png


Thanks!

 

If this fixed your issue, a Like and marking it as a Solution would mean a lot!
Shopify Developer | Helping eCommerce Stores Grow – cmsMinds (Shopify Partner)
Need help improving your Shopify store to stay ahead of market trends or need expert support?
 Connect with me at ujjawal@cmsminds.com
Darshan17
Shopify Partner
26 2 4

This is an accepted solution.

Hi, 

can you please confirm ?
This is what you have expected ? 

Darshan17_0-1747047375235.png

Thanks ! 

If this fixed your issue, a Like and marking it as a Solution would mean a lot!
Shopify Developer | Helping eCommerce Stores Grow – cmsMinds (Shopify Partner)
Need help improving your Shopify store to stay ahead of market trends or need expert support?
 Connect with me at ujjawal@cmsminds.com