Filters
Filters are how you can alter the outcome of numbers, strings, variables, and objects in Liquid. They empower you to reshape static and dynamic text, like transforming a string from lowercase to uppercase or conducting mathematical operations such as addition or division.
Filters must be placed within an output tag {{ }}
and are denoted by a pipe character |
.
The table below lists the Liquid filters that Naxai currently supports.
As filters generally modify an output, most must be in double curly braces.
Math Filters
Filter | Description |
---|---|
abs | Returns the absolute value of a number. |
at_least | Limits a number to a minimum value. |
at_most | Limits a number to a maximum value. |
ceil | Rounds an input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied. |
divided_by | Divides a number by another number. The result is rounded down to the nearest integer (that is the floor) if the divisor is an integer. |
floor | Rounds an input down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied. |
minus | Subtracts a number from another number. |
modulo | Returns the remainder of a division operation. |
plus | Adds a number to another number. |
round | Rounds a number to the nearest integer or, if a number is passed as an argument, to that number of decimal places. |
times | Multiplies a number by another number. |
Controlling rounding
divided_by
produces a result of the same type as the divisor — that is, if you divide by an integer, the result will be an integer. If you divide by a float (a number with a decimal in it), the result will be a float.
String Filters
Filter | Description |
---|---|
append | Adds the specified string to the end of another string. |
capitalize | Makes the first character of a string capitalized and converts the remaining characters to lowercase. |
downcase | Makes each character in a string lowercase. It has no effect on strings which are already all lowercase. |
escape | Escapes a string by replacing characters with escape sequences (so that the string can be used in a URL, for example). It doesn’t change strings that don’t have anything to escape. |
lstrip | Removes all whitespace (tabs, spaces, and newlines) from the left side of a string. It does not affect spaces between words. |
newline_to_br | Inserts an HTML line break (<br /> ) in front of each newline (\n) in a string. |
prepend | Adds the specified string to the beginning of another string. |
remove | Removes every occurrence of the specified substring from a string. |
remove_first | Removes only the first occurrence of the specified substring from a string. |
replace | Replaces every occurrence of the first argument in a string with the second argument. |
replace_first | Replaces only the first occurrence of the first argument in a string with the second argument. |
rstrip | Removes all whitespace (tabs, spaces, and newlines) from the right side of a string. It does not affect spaces between words. |
size | Returns the number of characters in a string or the number of items in an array. |
split | Divides a string into an array using the argument as a separator. split is commonly used to convert comma-separated items from a string to an array. |
strip | Removes all whitespace (tabs, spaces, and newlines) from both the left and right sides of a string. It does not affect spaces between words. |
strip_html | Removes any HTML tags from a string. |
strip_newlines | Removes any newline characters (line breaks) from a string. |
truncate | Shortens a string down to the number of characters passed as an argument. If the specified number of characters is less than the length of the string, an ellipsis (…) is appended to the string and is included in the character count. |
truncatewords | Shortens a string down to the number of words passed as an argument. If the specified number of words is less than the number of words in the string, an ellipsis (…) is appended to the string. |
upcase | Makes each character in a string uppercase. It has no effect on strings which are already all uppercase. |
url_decode | Decodes a string that has been encoded as a URL or by url_encode. |
url_encode | Converts any URL-unsafe characters in a string into percent-encoded characters. |
Array Filters
Filter | Description |
---|---|
compact | Removes any nil values from an array. |
concat | Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays. |
first | Returns the first item of an array. |
join | Combines the items in an array into a single string using the argument as a separator. |
last | Returns the last item of an array. |
map | Creates an array of values by extracting the values of a named property from another object. |
reverse | Reverses the order of the items in an array. reverse cannot reverse a string. |
size | Returns the number of characters in a string or the number of items in an array. |
slice | Returns a substring of one character or series of array items beginning at the index specified by the first argument. |
sort | Sorts items in an array in case-sensitive order. |
sort_natural | Sorts items in an array in case-insensitive order. |
split | Divides a string into an array using the argument as a separator. split is commonly used to convert comma-separated items from a string to an array. |
sum | Sums all items in an array. |
uniq | Removes any duplicate items in an array. |
where | Creates an array including only the objects with a given property value, or any truthy value by default. |
Date Filter
The date filter can convert a timestamp into a different date format. You can pass in parameters to the date filter to reformat the timestamp. For examples of these parameters, refer to strfti.me .
This page was last updated at {{ "now" | date: "%Y-%m-%d %H:%M" }}.
This page was last updated at 2023-07-07 14:07.
{% assign currentDay = "now" | date: "%A" %}
{% if currentDay == "Friday" %}
Have a great weekend!
{% endif %}
Default Filter
Default values can be added by specifying a Liquid Filter (use |
to distinguish the filter inline) with the name “default.”
If a default value is not provided and the field is missing or not set on the user, the field will be blank in the message.
Hi {{ contact.firstName | default: "Valued Customer" }}, thanks for using our product!
Updated about 1 year ago