I’m using Shopify and want to hook into customer tags, however they are case sensitive. So {% if customer.tags contains "wholesale" %}
is not the same as {% if customer.tags contains "Wholesale" %}
. My client may or may not stick to one case when applying tags so I want to guard against that in the future.
I would like to take an array, customer.tags, and convert all of the values to lowercase. I’m trying to work out the logic but am having trouble.
I want to put customer.tags into a new array which isn’t working.
{% assign newArray = customer.tags %}
{{ newArray }}
What am I doing wrong?
3
Answers
You could use the
downcase
filter for this:Note:
downcase
just works for ASCII characters. If you need to search for strings with accented letters or other Unicode characters then this won’t be enough.Another solution as you use the “contains” operator would be to skip the “w”.
Something like {% if customer.tags contains ‘holesale’ %} should work.
if you would like to keep
customer.tags
as an array so you can keep usingcontains
in a simpleif
statement (like your example). You could also chain a couple of liquid filters together to turn all of the strings within the array to lowercase.Example:
Explanation:
,