Applying a filter
Global, predefined functions that change the output of a variable.
Filters are global, predefined functions that change the output of a variable. Filters are used within an output and separated by the vertical bar character (|
).
Input
{{ "/my/fancy/url" | append: ".html" }}
Output
/my/fancy/url.html
Multiple filters can be used on one output. They are applied from left to right.
Input
{{ "world!" | capitalize | prepend: "Hello " }}
Output
Hello World!
Available filters
The following filters are supported (the links will open in Liquid’s documentation):
Filter | Function |
---|---|
abs |
returns the absolute value of a number |
append |
concatenates two strings and returns the concatenated value |
at_least |
limits a number to a minimum value |
at_most |
limits a number to a maximum value |
capitalize |
capitalizes the first character of a string |
ceil |
rounds the input up to the nearest whole number |
compact |
removes nil values from array |
concat |
concatenates multiple arrays |
date |
converts timestamps and well-formatted date strings into other formats |
default |
specify a default value if a value is nil , false , or empty |
divided_by |
divides a number by another number |
downcase |
make each character in a string lowercase |
escape |
escapes special characters in a string with escape sequences |
escape_once |
escapes a string without changing existing entities |
first |
returns the first item of an array |
floor |
rounds the input down to the nearest whole number |
join |
combines the items in an array together into a single string using separator |
last |
returns the last item of an array |
lstrip |
removes whitespace from the left side of a string |
map |
creates an array of values by extracting the values of a named property from another object |
minus |
subtracts a number from another number |
join |
combines the items in an array together into a single string using separator |
modulo |
returns the remainder of a division operation |
newline_to_br |
replaces every newline (\n ) in a string with an HTML line break (<br /> ) |
plus |
adds a number to another number |
prepend |
adds the specified string to the beginning of another string |
remove |
removes every occurence of the specified substring from the string |
remove_first |
removes only the first occurence of the specified substring from the string |
replace |
replaces every occurence of a substring in a string with another substring |
replace_first |
replaces only the first occurence of a substring in a string with another substring |
reverse |
reverses the order of the items in an array |
round |
rounds a number to the nearest integer (or number of decimal places) |
rstrip |
removes all whitespace from the right side of a string |
size |
returns the number of characters in a string or the number of items in an array |
slice |
returns a substring from the index and for the length specified |
sort |
sorts items in an array in a case-sensitive order |
sort_natural |
sorts items in an array in a case-insensitive order |
split |
divides a string into an array using a separator |
strip |
removes whitespace from both sides of a string |
strip_html |
removes any HTML tags from a string |
strip_newlines |
removes any newline characters from a string |
times |
multiplies a number by another number |
truncate |
shortens a string to the requested number of characters |
truncatewords |
shortens a string to the requested number of words |
uniq |
removes any duplicate items in an array |
upcase |
makes each character in a string uppercase |
url_decode |
decodes a string that has been encoded as a URL |
url_encode |
converts any URL-unsafe characters in a string into percent-encoded characters |
where |
creates an array including only the objects with a given property value |