Finding a partial match with "contains"

Shopify Partner
122 0 27
{%- for tag in item.product.tags -%}{%- if item.product.tags contains 'depot' -%}<p>depot</p>{%- break -%}{%- endif -%}{%- endfor -%}

Hello,

 

I'm trying to find a partial match of one of the product tags on my cart page.  The tags will look like this "depot .10"

 

The code I'm using will find it if I insert "depot .10" but not if I only search for the word "depot".  I will have several possible tags with the word "depot" in it.

 

Any ideas?

 

Thank you in advance

Tourist
4 1 0

Try something like this:

{% for tag in product.tags %}
  {% if tag contains 'depot' %}
    "depot" was found in: {{ tag }}
  {% endif %}
{% endfor %}

NOTE:  The "contains" search string is CaSe sensitive.

To overcome case sensitivity, try this:

{% for tag in product.tags %}
  {% capture casetag %}{{tag | downcase}}{% endcapture %}
  {% if casetag contains 'depot' %}
    "depot" was found in: {{ tag }}
  {% endif %}
{% endfor %

 

Hope this helps.

0 Likes