Ad

Filter Out Collection Name From Product Tag List (display) Shopify

- 1 answer

I would love to know how to remove from display tags that are used to automatically create collections (they appear in other product section). For example:

$125
COLLECTION : BUSINESS
TAGS: AUTUMN BUSINESS BLACK

So that BUSINESS tag (which is used to form a BUSINESS collection ) is filtered out.

Tries the following 'straightforward' solution:

    {% for tag in product.tags %}
        {% unless tag == 'Business' or tag == 'Vintage' or tag ==  or tag == 'Boho' %}
            display {{ tag }} link
        {% endunless %}
    {% endfor %}

Which did not see to Work Thanks

Ad

Answer

Sometimes multiple conditions in if statements don't work so well in liquid. (See here and here.)

You could try something like this instead:

{% assign excluded_tags = "Business,Vintage,Boho" | split: "," %}

{% for tag in product.tags %}
  {% unless excluded_tags contains tag %}
    {{ tag }}
  {% endunless %}
{% endfor %}

EDIT:

I just tested your code again, and even with the typo or tag == or..., it still works fine for me (just a warning on save).

Another suggestion is perhaps it's got to do with capitalisation. E.g. If you have a tag BUSINESS, then tag == 'Business' is not going to work. The capitalisation needs to be consistent.

EDIT 2:

From comment below:

I was thinking how to automatically populate excluded tags by the names of the collections of a product.

You can use map to get an array of collection titles:

{% assign excluded_tags = product.collections | map: 'title' %}
Ad
source: stackoverflow.com
Ad