How to exclude certain collections from results on product page?

This code returns all collections for a product. I’m trying to exclude some of the returned collections based on some keywords the same way as product.tag but it’s not working.


**Related Content:**  This product is part of

{% for product_collection in product.collections limit:10 %}

{% assign product_collection = product.collections %}
{% if product_collection contains "best" or product_collection contains "men" or product_collection contains "women" %}
excluded
{% else %}

{{ product_collection.title | link_to: product_collection.url }},
{% endif %}
{% endfor %} Collections

You can use the {% continue %} tag to go to the next item in the for loop. So:

{% assign product_collection = product.collections %}
{% if product_collection contains "best" or product_collection contains "men" or product_collection contains "women" %}
{% continue %}
{% else %}

See the iteration-flow documentation here:

{% continue %} doesn’t work. Something is wrong with my if statement, the conditions are not met and the code is executed by else codition.

OK. I figured it out.

the title match is case sensitive and the if statement should look in product.collection.title
This code will create links to related collections URLs based on product tags in product page

Here is the working code


**Related Content:**  This product is part of
    {% for product_collection in product.collections limit:10  %}

{% if product_collection.title  contains 'Best' or product_collection.title contains "Most" or product_collection.title contains "Latest" %} 
  title has a match and has been removed 
  {% else %}

 {{ product_collection.title | link_to: product_collection.url }}, 
{% endif %}
{% endfor %} Collections