New Shopify Certification now available: Liquid Storefronts for Theme Developers

Using code to hide empty metafields - Liquid to JSON

Shopify Partner
1 0 0

Hi all, I use some liquid conditional statements that hides empty metafields from rendering and wish to build it into a JSON metafield in order to add it as a dynamic source in a template.


Is this possible at all? I have attempted to follow some forum suggestions but get error messages on save.


The code is:


{% if product.metafields.custom.brand != blank %}
<div> <B>Brand:</B> {{ product.metafields.custom.brand }}</div>
{% endif %}

{% if product.metafields.custom.model != blank %}
<div> <B>Model:</B> {{ product.metafields.custom.model }}</div>
{% endif %}


and so on. Or is there another way to add conditional logic to metafields added in a template so as not to leave blank spaces?



Replies 0 (0)