Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Is there way to hide existing section when metaobject definition used. I have large product catalog and instead of creating different product templates, looking for the way where easy to apply some edits to code section file to display dynamic content if section exists with metaobject definition.
Example before/after section used as metaobject with many different fields and want to display section only when metaobject definition exists else want to hide it.
Thanks.
Hey.
You can use this code:
{% if product.metafields.custom.yourMetafieldName.value != blank %}
// Your Section
{%- endif %}
This will make code in the if-statement only appear if the metafield is not empty.
Please note that you need to edit the theme in the right place to make this change work.
Greetings
It is for metafield definition. Looking for metaobject as there are multiple fields included in it.
Hey.
I see. Sorry for the confusion.
You can use this code:
{% if product.metafields.custom.yourMetaObject %}
// Your section
{%- endif %}
To make this work, you first have to create a metaobject in content → metaobjects. After that, you have to assign the metaobject as a product metafield.
With the code I mentioned above, the section will show up when your product has a metaobject assigned.
Having a similar issue in an Image with Text section, and I just can't figure out where to place the "if" code mentioned above so that this section will not appear on my page when there are no values in these metafields.
"0c50a836-5c60-4c74-9a03-a4f198b3f2f0": {
"type": "image-with-text",
"blocks": {
"template--14834752159857__0c50a836-5c60-4c74-9a03-a4f198b3f2f0-heading-1": {
"type": "heading",
"settings": {
"heading": "{{ metaobject.event_title.value }}",
"heading_size": "h2"
}
},
"template--14834752159857__0c50a836-5c60-4c74-9a03-a4f198b3f2f0-text-1": {
"type": "text",
"settings": {
"text": "<p>{{ metaobject.event_date_and_time | metafield_tag }}<\/p>",
"text_style": "body"
}
},
"template--14834752159857__0c50a836-5c60-4c74-9a03-a4f198b3f2f0-button-1": {
"type": "button",
"disabled": true,
"settings": {
"button_label": "Button label",
"button_link": "",
"button_style_secondary": false
}
}
Shopify and our financial partners regularly review and update verification requiremen...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025