Using filters in Liquid
Filters can be used to dynamically transform your data in rendering.
How to use a filter in Liquid
Filters are always used in the same way, inside a liquid tag and after a |
, and it's possible to use several filters one after the other. Some filters can also take a parameter to modify their behavior.
{{ your data | filter_1 | filter_2 }}
Example: {{ "apple" | upcase }}
which will display APPLE
after rendering
Example with parameters: {{ 2 | plus: 2 | minus: 1 }}
which will display 3
after rendering
Of course you can use filters with variables that you define within the template and variables that are already present within the template.
Example: {{ order.total_price | plus: 12 }}
Basic filters available in Liquid
There are many filters in Liquid which are already documented, you can check the official documentation here : https://shopify.github.io/liquid/
Custom Liquid filters in Splio
Splio has developed additional filters, for specific purposes, here's an exhaustive list of them.
Date filters
Filters to facilitate date operations directly within the templates. By default the returned date format of theses liquid filters is 2025-04-10 11:32:00
, but you can modify this format by using the liquid date
filter. List of implemented filters:
- add_years
- add_months
- add_days
- add_hours
- add_minutes
The parameter can be either positive or negative. If it’s negative this mean that it’s a subtraction.
Examples:
Liquid usage | Result |
---|---|
{{ “now” | add_days: -1 | date: “%Y-%m-%d” }} | “2025-04-09” (today’s date: 2025-04-10) |
{{ “2025-01-01 00:00:00” | add_hours: 2 }} | “2025-01-01 02:00:00” |
{{ “2025-07-12 08:00:00” | add_minutes: 24 }} | “2025-07-12 08:24:00” |
{{ “2025-01-12 09:12:00” | add_months: -3 }} | “2024-10-12 09:12:00” |
Unix timestamps filter
There's also a special filters to handle unix timestamp if you need, todate
will transform a unix timestamp into a date that you can manipulate easily, to change it's format !
Examples:
Liquid usage | Result |
---|---|
{{ 300695719 | todate }} | 1979-07-13 06:35:19 +0000 |
{{ 300695719 | todate | date: "%Y-%m-%d" }} | 1979-07-13 |
Hashing filters
Filters to allow users to perform hashing operations directly within the templates. There is no parameter for theses filters and they can be used when you need to change the display of specific data when needed.
- md5
- sha1
- sha256
Examples:
Liquid usage | Result |
---|---|
{{ "test" | sha256 }} | 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 |
{{ "test" | md5 }} | 098f6bcd4621d373cade4e832627b4f6 |
{{ "test" | sha1 }} | a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 |
Type casting filters
Filters for type casting to enable conversion between data types within the rendering. This is usually advanced usage as it requires to understand the type of your data and why you need to transform it. It allows to use other filters that are specific for a type or to normalize the way data is displayed !
- integer
- decimal
- string
- boolean
Examples:
Liquid usage | Result | Purpose |
---|---|---|
{{ 12.1 | string }} {{ 12 | decimal | string }} {{ 12.35123 | string }} | 12.10 12.00 12.35 | Normalize the way decimals are displayed to always have 2 digits. |
{{ 12 | string | split: "" | last }} | 2 | Transform an integer into a string so you can use string specific filters. |
{{ "test" | boolean }} {{ "" | boolean }} | true false | Transform a string into a boolean to check for emptiness |
Updated 3 days ago