Using code to hide empty metafields - Liquid to JSON

Using code to hide empty metafields - Liquid to JSON

SScanlan
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:

 

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

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

 

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?

 

H

Replies 0 (0)