How can I hide empty metafields effectively?

How can I hide empty metafields effectively?

chriswillemse
Tourist
3 0 1

I am trying to hide my metafields when empty, but cant seem to get it right

Replies 3 (3)

NomtechSolution
Astronaut
1245 113 159

Add != blank with metafield in if condition

{% if product.metafields.namespace.key != blank %}
  <div class="metafield">{{ product.metafields.namespace.key }}</div>
{% endif %}
chriswillemse
Tourist
3 0 1

Hi, Thank you for the quick response! Could you please tell if this is the correct section to add in the above bit of code? Is it possible to let me know where to add this in exactly? We have 2 tabs/ metafields we need only to be available on some items, more intricate items that warrant extra information, for other items these extra fields are not necessary or would not have enough information to make it worth while for these to be visible. These 2 are ''Specifications'' and ''Who is this for?''

 

 

},
"5037f519-1343-4167-a315-31c99471503f": {
"type": "tab",
"settings": {
"column": "primary",
"title": "Specification",
"text": "<p>{{ product.metafields.custom.specification_wolf_king_gt | metafield_tag }}<\/p>",
"image_width": 1000,
"align": "center",
"link": "",
"tab_content": "",
"open": false
}
},
"c13717d6-5def-40f5-9684-68f8f103b0d4": {
"type": "tab",
"settings": {
"column": "secondary",
"title": "Who is this scooter for?",
"text": "<p>{{ product.metafields.custom.who_is_this_for_ | metafield_tag }}<\/p><p><\/p>",
"image_width": 1000,
"align": "center",
"link": "",
"tab_content": "",
"open": false

chriswillemse_0-1684832901966.png

 

chriswillemse
Tourist
3 0 1

Good day, just following up on this query, would really appreciate assistance on this matter 🙂