I am facing an issue with the contains for a product tag that includes “:” , could this be an issue with the operator or is this documented somewhere?
for example if a product has the following tag config:max_quantity_per_order:10 and I check if the product contains a sub string of this tag using `product.tags contains “config:max_quantity_per_order” or “config:max_quantity_per_order:” it doesn’t work it returns false.
I think you are referring to something else. I am talking about liquid code to search for specific tag in a product. I found that if the tag contains “:” it does not work when checking in product.tags, if you do a for tag in product.tags and check there it works. I might create an Issue directly in github to get more info.
However, you’re running contains check against product.tags, which is an array and in this case the match must be exact (like it is in my example), you can’t match a substring when using contains with arrays.
So you may do it like this:
{% assign tags_string = tags | join: "|||" %}
{% if tags_string contains "config:max_quantity_per_order:" %}
{% assign max_qty = tags_string | split: "config:max_quantity_per_order:" | last | times: 1 %}
{% if max_qty > 0 %}
<!-- limit max qty to {{ max_qty }}! -->
{% endif %}
{% endif %}
Thanks @tim_1 that confirms the weird behavior that I was experiencing. So if it is for a specific tag in a for loop contains correctly works as a substring.
If it is for .tags which is an array, it stops working as a substring and works as an exact match.