I am adding a custom attribute to the bottom of the product card on my theme. I am currently using
{%- if product.tags != ‘blank’ -%}
{{ tags }}
{%- 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 -%}
{{ tags }}
{%- 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 -%}
{{ tag }}
{%- 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.