Filters

Simple functions that alter the values of data within your Live Editor site design.

Filters in Liquid are simple functions that allow you to manipulate data. They are typically used in {{ output }} or {% assign %} blocks.

Consider this example of using the upcase filter to transform a string to all uppercase:

{{ 'I am not yelling' | upcase }}

Output

I AM NOT YELLING

Filters can also be chained together, and some accept arguments. Filters are applied in order from left to right.

      {{ 'I am not yelling' | replace: 'yelling', 'whispering' | upcase }}
      

Output

I AM NOT WHISPERING

There are many filters available for your use, so here they are, sorted into categories:


Base filters

default
Lets you specify a fallback in case a value doesn’t exist.

Array filters

join
Combine array elements into a list with delimiter.
first
Get the first element of an array.
last
Get the last element of an array.
map
Grabs a given attribute’s value from each element in an array and combines it all into a new array.
size
Number of elements within an array.
sort
Sorts an array alphabetically by a given attribute’s values for each element.

HTML filters

asset_url
Returns the URL of an asset within the theme’s assets folder.
img_tag
Generate an HTML <img> tag.
script_tag
Generates an HTML <script> tag for including JavaScript files.
stylesheet_tag
Generates an HTML <link> tag for including CSS files.
url_escape
Replaces all characters not allowed in URLs with their URL-encoded equivalents.
url_param_escape
Replaces all characters not allowed in URLs with their URL-encoded equivalents, including the ampersand (&) character.

Math filters

ceil
Rounds a number up to the nearest integer.
divided_by
Divides a number into another number, rounding the result down to the nearest integer.
floor
Rounds a number down to the nearest integer.
minus
Subtracts a number by another number.
modulo
Divides 2 numbers and returns the remainder.
plus
Adds a number to another.
round
Rounds a number to the nearest integer or specified number of decimals.
times
Multiplies a number by another.

String filters

append
Add a string to the end of another string.
camelcase
Converts a string into camelCase.
capitalize
Capitalizes the first word in a string.
date
Converts a timestamp into another date and/or time format.
downcase
Convert a string to all lowercase.
escape
HTML-escapes a string.
md5
Converts a string into an MD5 hash.
newline_to_br
Replaces line breaks in a string with HTML <br> tags.
pascalcase
Converts a string into PascalCase.
pluralize
Return a word or its plural form depending on the value of a number.
prepend
Prepend a string to the beginning of another string.
remove
Remove all occurrences of a substring from a string.
remove_first
Remove the first occurrence of a substring from a string.
replace
Replace all occurrences of a substring with a string.
replace_first
Replace the first occurence of a substring with a string.
size
Returns number of characters within a string.
slice
Slices a string by an offset and length.
split
Divides a string into an array based on a delimiter.
strip
Trims whitespace characters (spaces, tabs, newlines) from the beginning and end of a string.
lstrip
Trims whitespace characters (spaces, tabs, newlines) from the beginning of a string.
rstrip
Trims whitespace characters (spaces, tabs, newlines) from the end of a string.
strip_html
Remove all HTML tag markup from a string.
strip_newlines
Removes all newline characers from a string.
truncate
Cuts a string down to a given number of characters.
truncatewords
Cuts a string down to a given number of words.
upcase
Convert a string to all uppercase.