This document is a work in progress, please let us know what else we can add!
Filters
Abs
Returns the absolute value of a number or string that only contains a number.
{{ -24 | abs }} -> 24
{{ "-1.23" | abs }} -> 1.23
Append
Appends characters to a string
Alternatively, you may use the '+' or '~' operators rather than this filter.
{{ 'sales' | append: '.jpg' }} -> sales.jpg
Camelize
Converts a dash-separated string into CamelCase
{{ 'coming_soon' | camelize }} -> ComingSoon
Capitalize
Capitalizes the first word in a string.
{{ 'capitalize me' | capitalize }} -> Capitalize me
Ceil
Rounds an output up to the nearest integer.
{{ 4.6 | ceil }} -> 5
{{ 4.3 | ceil }} -> 5
Date
Converts a timestamp into another date format
{{ article.published_at | date: "%a, %b %d, %y" }} -> Tue, Apr 22, 14
Common variables
%d Day of the month (decimal number)
%m Month (decimal number)
%b Month (abbreviated)
%B Month (full name)
%y Year (2 digit)
%Y Year (4 digit)
Date Math
Add or subtract time to a timestamp
{{ '2020-05-19' | date_parse | date_math: 1, 'days' | date: '%Y-%m-%d'}} -> 2020-05-20
{{ '2020-05-19' | date_parse | date_math: -1, 'days' | date: '%Y-%m-%d'}} -> 2020-05-18
{{ '2020-05-19' | date_parse | date_math: -1, 'years' | date: '%Y-%m-%d'}} -> 2019-05-19
Date Parse
Takes a date represented by a string and converts it into a timestamp.
By default, it recognizes strings in iso 8601 date format. Other time formats must be specified.
{{"2020-05-15" | date_parse}} -> ISO, will work without specification
{{"2020-05-15T15:32:10" | date_parse}} -> ISO, will work without specification
{{ "05.15.20" | date_parse: "%m.%d.%y"}} -> Not ISO, date format needs to be specified
{{ "May 15, 2020" | date_parse: "%B %m, %Y}} -> Not ISO, date format needs to be specified
Decode
Converts a string encoded in a specified encoding format into UTF-8
{{my_string | decode: "iso-8859-1" }} -> Will convert a iso-8859-1 (Latin-1) string to UTF-8
Decode Base64
Converts a string encoded in the base64 encoding specified in RFC 2045 - MIME into UTF-8
{{my_64bit_encoded_string | decode_base64 }}
Default
Sets a default value for any variable with no assigned value. Can be used with strings, arrays, and hashes.
The default value is returned if the variable resolves to nil or an empty string "".
A string containing whitespace characters will not resolve to the default value.
Dear {{ customer.name | default: "customer" }}
<!-- If customer.name is not defined -->
Dear customer
<!-- If customer.name is "" -->
Dear customer
<!-- If customer.name is " " -->
Dear
(note the hidden " " space after Dear)
<!-- If customer.name is "Chris" -->
Dear Chris
Divided by
Divides an output by a number. The output is rounded down to the nearest integer
Alternatively, you may use the '/' operator rather than this filter.
<!-- product.price = 200 -->
{{ product.price | divided_by: 10 }} -> 20
<!-- product.price = 195 -->
{{ product.price | divided_by: 10 }} -> 19
Operators
Tags