Filters: Standard

Last updated on June 18, 2024

Use this document to guide you in using standard Liquid filters.

abs

Returns the absolute value of a number.

Input

Output

Input

Output

will also work on a string if the string only contains a number.

Input

Output

append

Concatenates two strings and returns the concatenated value.

Input

Output

can also be used with variables:

Input

Output

can be used with a number, it will return a string:

Input

Output

at_least

Limits a number to a minimum value.

Input

Output

Input

Output

at_most

Limits a number to a maximum value.

Input

Output

Input

Output

capitalize

Makes the first character of a string capitalized.

Input

Output

only capitalizes the first character of the string, so later words are not affected:

Input

Output

ceil

Rounds the input up to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.

Input

Output

Input

Output

Input

Output

Here the input value is a string:

Input

Output

concat

Concatenates (joins together) multiple arrays. The resulting array contains all the items from the input arrays.

Input

Output

You can string together filters to join more than two arrays:

Input

Output

date

Converts a timestamp into another date format. The format for this syntax is the same as . You can use the standard date formatting for UNIX. Available directives for time and date are listed here.

Input

Output

Input

Output

works on strings if they contain well-formatted dates:

Input

Output

To get the current time, pass the special word (or ) to date:

Input

Output

Note that the value will be the current time of when the page was last generated from the template, not when the page is presented to a user if caching or static site generation is involved.

default

Allows you to specify a fallback in case a value doesn’t exist. will show its value if the left side is , , or .

Input

Output

In this example, is defined, so the default value is not used.

Input

Output

In this example, is empty, so the default value is used.

Input

Output

To allow variables to return instead of the default value, you can use the parameter.

Input

Output

divided_by

Divides a number by the specified number. The result is rounded down to the nearest integer (that is, the floor) if the divisor is an integer.

Input

Output

Input

Output

Controlling rounding

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.

For example, here the divisor is an integer:

Input

Output

Here it is a float:

Input

Output

Changing variable types

You might want to use a variable as a divisor, in which case you can’t simply add .0 to convert it to a float. In these cases, you can assign a version of your variable converted to a float using the filter.

In this example, you’re dividing by a variable that contains an integer, so you get an integer:

Input

Output

Here, you multiply the variable by to get a , then divide by the instead:

Input

Output

downcase

Makes each character in a string lowercase. It has no effect on strings that are already all lowercase.

Input

Output

Input

Output

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.

Input

Output

Input

Output

first

returns the first item of an array.

Input

Output

Input

Output

floor

Rounds a number down to the nearest whole number. Liquid tries to convert the input to a number before the filter is applied.

Input

Output

Input

Output

Input

Output

Here the input value is a string:

Input

Output

join

Combines the items in an array into a single string using the argument as a separator.

Input

Output

last

Returns the last item of an array.

Input

Output

Input

Output

lstrip

Removes all whitespaces (tabs, spaces, and newlines) from the beginning of a string. The filter does not affect spaces between words.

Input

Output

map

Important

We have overwritten the map filter so it will not work in the standard way. Visit the reference for the Insites map filter to learn more.

minus

Subtracts a number from another number.

Input

Output

Input

Output

Input

Output

modulo

Returns the remainder of a division operation.

Input

Output

Input

Output

Input

Output

newline_to_br

Replaces every newline with an HTML line break .

Input

Output

plus

Adds a number to another number.

Input

Output

Input

Output

Input

Output

prepend

Adds the specified string to the beginning of another string.

Input

Output

You can also prepend variables:

Input

Output

remove

Removes every occurrence of the specified substring from a string.

Input

Output

remove_first

Removes only the first occurrence of the specified substring from a string.

Input

Output

replace

Replaces every occurrence of an argument in a string with the second argument.

Input

Output

replace_first

Replaces only the first occurrence of the first argument in a string with the second argument.

Input

Output

reverse

Reverses the order of the items in an array. cannot reverse a string.

Input

Output

cannot be used directly on a string, but you can split a string into an array, the array and rejoin it by chaining together filters:

Input

Output

round

Rounds an input number to the nearest or, if a number is specified as an argument, to that number of decimal places.

Input

Output

Input

Output

Input

Output

rstrip

Removes all whitespace (tabs, spaces, and newlines) from the right side of a string.

Input

Output

size

Returns the number of characters in a string, the number of items in an array, or the number of bytes needed to store the integer in memory. can also be used with dot notation (for example, 42). This allows you to use size inside tags such as conditionals.

Input

Output

Input

Output

Using dot notation:

slice

Returns a substring of 1 character beginning at the index specified by the argument passed in. An optional second argument specifies the length of the substring to be returned.

String indices are numbered starting from 0.

Input

Output

Input

Output

Input

Output

If the first parameter is a negative number, the indices are counted from the end of the string:

Input

Output

sort

Sorts items in an array by a property of an item in the array. The order of the sorted array is case-sensitive, meaning all capitalized strings will come before any lowercase strings.

Input

Output

sort_natural

Sorts items in an array by a property of an item in the array. The order of the sorted array is case-insensitive.

Input

Output

split

Divides an input string into an array using the argument as a separator. is commonly used to convert comma-separated items from a string to an array.

Input

Output

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.

Input

Output

strip_html

Removes any HTML tags from a string.

Input

Output

strip_newlines

Removes any newline characters (line breaks) from a string.

Input

Output

times

Multiplies a number by another number.

Input

Output

Input

Output

Input

Output

truncate

shortens a string down to the number of characters passed as a parameter. If the number of characters specified is less than the length of the string, an ellipsis (…) is appended to the string and is included in the character count.

Input

Output

Custom ellipsis

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 , since the ellipsis counts as 3 characters.

Input

Output

No ellipsis

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:

Input

Output

truncatewords

Shortens a string down to the number of words passed as the argument. If the specified number of words is less than the number of words in the string, an ellipsis (…) is appended to the string.

Input

Output

Custom ellipsis

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.

Input

Output

No ellipsis

You can avoid showing trailing characters by passing a blank string as the second parameter:

Input

Output

uniq

Removes any duplicate elements in an array.

Input

Output

upcase

Makes each character in a string uppercase. It has no effect on strings that are already all uppercase.

Input

Output

Input

Output

url_decode

Decodes a string that has been encoded as a URL or by .

Input

Output

url_encode

Converts any URL-unsafe characters in a string into per cent-encoded characters.

Input

Output

Input

Output

where

Creates an array comprising objects with a specified property value or any value by default.

For example, suppose you have a list of products and want to display kitchen products separately. By employing , you can generate an array containing only those products under the of .

Input

Output

Consider instead, a scenario where you have a list of products, and your objective is to display only those available for purchase. In this case, you can employ with only a property name, omitting a specific target value. This action includes all products with a truthy value.

Input

Output

The filter can also be used to find a single object in an array when combined with the first filter. For example, say you want to show off the shirt in your new fall collection.

Input

Output

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.