I stumbled across this reference at the bottom of the liquid variables reference page for handling filters as a liquid variable.
{{ _filters['view_name.field_name'] | split:"," | sql_quote | join:"," }}
That end portion with the “split” and “join” functions, I decided to try something with a “remove” function that ended up working.
For example, if the “view_name.field_name” in the filter was “Mississippi” and I used the following liquid filter, we would get the following returned.
{{ _filters['view_name.field_name'] | remove:"i"}}
returns: "Msssspp"
Another use case would be stripping the “%” from a “contains” filter to just get the value elsewhere.
Is there any documentation that discusses the different operators/functions like “split”, “join”, “remove” and how to best use them?
Hi Minerkt,
You can find more information and examples about liquid template engine here:
- Split:
- Join:
- Remove:
- Full documentation:
Happy debugging!
Leo
Can we use lower or upper function around liquid variables? I am getting error..
{%- if lower(user_email_domain) == 'yahoo.com' -%}
how to overcome this issue? please help.
Hi @rkancha2024 , you can't use sql type functions such as lower() within liquid.
However, you can use what are called liquid filters to achieve a similar result.
In this case, we would need to make user_email_domain._value into lowercase.
The syntax could look like {% if user_email_domain._value | lowercase == 'yahoo.com' %}
However, from my testing, it seems like adding filter statements into a conditional doesn't work as I would like, so we should take this approach instead.
Please note though, that gettings field values such as _value can only be used in action/html/link parameters as according to the docs.
If you want to evaluate in sql you would just use standard CASE WHEN lower(user_email_domain) = 'yahoo.com' THEN xxx ELSE END kind of syntax.