New Shopify Certification now available: Liquid Storefronts for Theme Developers

Hide section when metafields are empty

Solved
lana-mukti
New Member
4 0 0

 

I have added a text + image section onto the product page with content pulling from product metafields, but still setting the section heading via 'customise' in the theme editor. But when the metafields are blank, the heading still shows. how can I ensure the heading is also hidden when the metafields are blank?

Accepted Solution (1)
StoreWatchers
Trailblazer
203 29 31

This is an accepted solution.

Hi, @lana-mukti 

Greetings from the Store Watchers Support Team! Happy to help you today.

 

You can put this condition:

 

{% if product.metafields.namespace.key != blank %}
 // Put the heading tags within this condition
{% endif %}

 

 

Replace namespace with the actual namespace of the metafield and key with the key of the metafield. 

You can use this code snippet within the relevant section of your product page template to control the visibility of metafields based on their values. Repeat this code for each metafield you want to conditionally display.

Remember to adjust the code to match the structure and naming of your metafields.

 

Let me know If need further assistance

 

Regards,

Store Watchers Support Team

StoreWatchers - Automate testing for your Shopify store in seconds


If you find my reply helpful, please hit Like and Mark as Solution
Visit us: App Store | Website | FAQs

View solution in original post

Replies 2 (2)
StoreWatchers
Trailblazer
203 29 31

This is an accepted solution.

Hi, @lana-mukti 

Greetings from the Store Watchers Support Team! Happy to help you today.

 

You can put this condition:

 

{% if product.metafields.namespace.key != blank %}
 // Put the heading tags within this condition
{% endif %}

 

 

Replace namespace with the actual namespace of the metafield and key with the key of the metafield. 

You can use this code snippet within the relevant section of your product page template to control the visibility of metafields based on their values. Repeat this code for each metafield you want to conditionally display.

Remember to adjust the code to match the structure and naming of your metafields.

 

Let me know If need further assistance

 

Regards,

Store Watchers Support Team

StoreWatchers - Automate testing for your Shopify store in seconds


If you find my reply helpful, please hit Like and Mark as Solution
Visit us: App Store | Website | FAQs
Markas_Suika
Visitor
2 0 1

Hi, this is not the first thread I encounter, you tell the code but where to put it most of the people can't find, so do I. Can you specify where this code should ho?