All things Shopify and commerce
I am adding a custom attribute to the bottom of the product card on my theme. I am currently using
{%- if product.tags != 'blank' -%}
<div class="productTag">{{ tags }}</div>
{%- endif -%}
statement to display the custom attribute as shown in screenshots below. The problem is that it will also show on every other product. I have tried a hundred different ways and nothings seems to work. I have tried if != blank, nil, empty, "" and each return the same result. The blank or empty do not return a result unless in single quotes ( 'blank' ). I have also tried for tag in product.tags, or if x contains y. I just need the custom piece to NOT display if the product does not have a tag assigned. Please help!
Try this
{%- if product.tags.size > 0 -%}
<div class="productTag">{{ tags }}</div>
{%- endif -%}
using size > 0 does not seem to work either. When used, it removes the box altogether from the product card, even ones with a tag.
Means statement is working.
The one you are using {%- if product.tags != 'blank' -%} was not working becasue product.tags is an array not a string.
make sure you have defined the {{ tags }}
Still not sure then once try to print the tags in a loop
e.g.
{%- if product.tags.size > 0 -%}
{%- for tag in product.tags -%}
<p>{{ tag }}</p>
{%- endfor -%}
{%- endif -%}
Ok thank you. When trying to print the tags in a loop with the above code, it does not display anything on the product either.
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025