Last updated
Last updated
Filters are simple methods that modify the output of numbers, strings, variables and objects. They are placed within an output tag {{
}}
and are denoted by a pipe character |
.
In the example above, item
is the object, title
is its attribute, and upcase
is the filter being applied.
Some filters require a parameter to be passed.
Multiple filters can be used on one output. They are applied from left to right.
Array filters change the output of arrays. Array is a synonym to list. For example, order.line_items
is an array of line items or order.transactions
is an array of transactions.
Joins the elements of an array with the character passed as the parameter. The result is a single string.
Returns the first element of an array.
You can use first
with dot notation when you need to use the filter inside a tag.
Returns the last element of an array.
You can use last
with dot notation when you need to use the filter inside a tag.
Using last
on a string returns the last character in the string.
You can string together multiple concat
filters to combine more than two arrays:
Returns the item at the specified index location in an array. Note that array numbering starts from zero, so the first item in an array is referenced with [0]
.
Accepts an array element's attribute as a parameter and creates an array out of each array element's value.
Creates a flattened array of values taken from the specified attribute of each element of the input array.
Groups elements of the same property value. Creates an object where keys are the specified property value, and values are arrays of elements with the same property value.
Transforms an object by running each of the object's property value by a given filter. First parameter of map_values
is the filter name. The filter receives the object values one by one as its first parameter. All remaining parameters provided to map_values
are passed down to the given filter.
Reverses the order of the items in an array.
Returns the size of a string (the number of characters) or an array (the number of elements).
You can use size
with dot notation when you need to use the filter inside a tag.
Sorts the elements of an array by a given attribute of an element in the array.
The order of the sorted array is case-sensitive.
Example
Removes any duplicate instances of elements in an array.
Converts a timestamp into a specified date format.
To format a phone number associated with a shipping address:
To format a shipping address country as an ISO 3166 alpha-3 country code:
Converts a string, or object, into JSON format.
By default it produces a single-line JSON. You can pass an optional parameter "pretty"
, to get a multi-line, indented JSON output.
The json
filter is useful for debugging to check what are all available properties of a given object.
Allows parsing string in a format compliant with JSON file requirements into an object. It enables access to individual fields within the object using dot notation.
Returns a current or specified time converted to a desired time zone.
Math filters allow you to apply mathematical tasks.
Math filters can be linked and, as with any other filters, are applied in order of left to right. In the example below, minus
is applied first, then times
, and finally divided_by
.Copy
Returns the absolute value of a number.
abs
will also work on a string if the string only contains a number.
Limits a number to a maximum value.
Limits a number to a minimum value.
Rounds an output up to the nearest integer.
Liquid tries to convert the input to a number before the filter is applied.
Divides an output by a number. The output is rounded down to the nearest integer.
Rounds an output down to the nearest integer.
Subtracts a number from an output.
Divides an output by a number and returns the remainder.
Adds a number to an output.
Rounds the output to the nearest integer or specified number of decimals.
Multiplies an output by a number.
Convert a number into a string, rounding the number to keep only the given number of decimals.
The difference between round
and to_fixed
it that round
returns a number so it trims trailing zeros while to_fixed
will preserve them.
Appends characters to a string.
Capitalizes the first word in a string
Converts a string into lowercase.
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.
Extracts a first number from a string. It works for integers (123), decimal numbers (123.45), and negative numbers (-123). The extracted number is still a text so it doesn't strip leading zeros (0123).
Extracts all numbers from a string. It works for integers (123), decimal numbers (123.45), and negative numbers (-123). The extracted numbers are still a text to preserve leading zeros (0123). The result is an array.
Calculates an MD5 hash from a string.
Inserts a <br > linebreak HTML tag in front of each line break in a string.
Adds the specified string to the beginning of another string.
Removes all occurrences of a substring from a string.
Removes only the first occurrence of a substring from a string.
Replaces all occurrences of a string with a substring.
Replaces the first occurrence of a string with a substring.
The slice
filter returns a substring, starting at the specified index. An optional second parameter can be passed to specify the length of the substring. If no second parameter is given, a substring of one character will be returned.
If the passed index is negative, it is counted from the end of the string.
Strips tabs, spaces, and newlines (all whitespace) from the left and right side of a string.
Strips tabs, spaces, and newlines (all whitespace) from the left side of a string.
Strips tabs, spaces, and newlines (all whitespace) from the right side of a string.
Strips tabs, spaces, and newlines (all whitespace) from the entire string.
Strips all HTML tags from a string.
Removes any line breaks/newlines from a string.
Truncates a string down to the number of characters passed as the first parameter. An ellipsis (...) is appended to the truncated string and is included in the character count.
truncate
takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.
The length of the second parameter counts against the number of characters specified by the first parameter. For example, if you want to truncate a string to exactly 10 characters, and use a 3-character ellipsis, use 13 for the first parameter of truncate
, since the ellipsis counts as 3 characters.
You can truncate to the exact number of characters specified by the first parameter and show no trailing characters by passing a blank string as the second parameter:
Truncates a string down to the number of words passed as the first parameter. An ellipsis (...) is appended to the truncated string.
truncatewords
takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.
You can avoid showing trailing characters by passing a blank string as the second parameter:
Converts a string into uppercase.
Converts any URL-unsafe characters in a string into percent-encoded characters.
Note that url_encode
will turn a space into a +
sign instead of a percent-encoded character.
This is a special filter available in Exporteo to facilitate the setup of an XML output template.
Replaces characters that are special characters in XML documents.
Concatenates (combines) an array with another array. The resulting array contains all the elements of the original arrays. concat
will not remove duplicate entries from the concatenated array unless you also use the filter.
Creates an array including only the objects with a given property value, or any value by default.
You can use a property name with where
that has no target value when that property is a or . For example, the of products.
Formats a phone number according to the . If a country calling code is not included in the phone number, then you can pass an country code as an additional parameter.
Converts a two-letter country code to its three-letter equivalent.
The filter has two parameters: a date format and a .
String filters are used to manipulate outputs and variables of the type.
An example use case for this filter is to calculate a checksum of a request payload, and include it in a request header. Such a checksum is required by some APIs, for example, the .
The split
filter takes on a substring as a parameter. The substring is used as a delimiter to divide a string into an array. You can output different parts of an array using .
Decodes a string that has been encoded as a URL or by .