Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I'm pretty new to all of this, apologies if this is a dumb question.
Let's say I've got a metaobject definition that includes a field of the "product" type, called "related_product". On each entry, I select the related product. On the page template for that metaobject, I want to display a button only if that referenced product is available.
In a custom liquid element, I'm finding that
{{ metaobject.related_product }}
kicks out the gid of the related product I selected on that entry. Great, so it's seeing that product
But I was hoping to do something like
{% if metaobject.related_product.available is "true" %}
Display button
{% endif %}
But can't seem to get anything like that to work. Any way to make something like that work?
Solved! Go to the solution
This is an accepted solution.
You need to use .value to get actual product object from the metafield reference:
https://shopify.dev/docs/api/liquid/objects/metafield
{% if metaobject.related_product.value.available %}
Display button
{% endif %}
is "true" is not a thing in Liquid.
Why not use metafields for this? Just asking.
Not sure but May be using metafields you can get more than gid so other info of the product.
This is an accepted solution.
You need to use .value to get actual product object from the metafield reference:
https://shopify.dev/docs/api/liquid/objects/metafield
{% if metaobject.related_product.value.available %}
Display button
{% endif %}
is "true" is not a thing in Liquid.
AHHHhhhh, thanks so much. I had already tried using .value but I had put it after .available
Basically, .value makes an object out of reference.
So you use it on the metafield reference and then can use object properties.
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025