IF Statement not working to display an item if tag not blank (Stiletto)

IF Statement not working to display an item if tag not blank (Stiletto)

MD883W
Tourist
6 0 2

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! 

 

Screenshot 2025-05-05 225309.pngScreenshot 2025-05-05 225242.png

 

 

Replies 4 (4)

Guleria
Shopify Partner
4147 809 1164

Try this

{%- if product.tags.size > 0  -%}
<div class="productTag">{{ tags }}</div>
{%- endif -%}

- Custom themes, UI/UX design, ongoing maintenance & support.
- Drop an email   if you are looking for quick fix or any customization
- Email: guleriathakur43@gmail.com Skype: live:navrocks1
- Try GEMPAGES a great page builder
MD883W
Tourist
6 0 2

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. 

Guleria
Shopify Partner
4147 809 1164

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 -%}
- Custom themes, UI/UX design, ongoing maintenance & support.
- Drop an email   if you are looking for quick fix or any customization
- Email: guleriathakur43@gmail.com Skype: live:navrocks1
- Try GEMPAGES a great page builder
MD883W
Tourist
6 0 2

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.