Last week our engineers updated our version of Liquid to the latest build, making several new filters available for use in our templates. Filters are methods that can modify the output of numbers, strings, variables, or objects, and are used to format content, manipulate arrays, and perform mathematical operations.
We've updated our Liquid Basics page with a full listing of available filters, but here's a brief look at what exactly has been added:
String Filters:
capitalize - Capitalizes the first word in a string.
default - Displays a default value for an empty variable.
replace_first - Replaces only the first instance of a string from the input with another.
slice - Returns a substring starting at a specified index.
split - Divides a string into an array based on a substring.
strip - Strips whitespace from a string.
lstrip - Strips whitespace from the left side of a string.
rstrip - Strips whitespace from the right side of a string.
uniq - Removes duplicate instances of an element.
url_encode - Replaces all characters in a string with their escaped variants for use in URLs.
Math Filters:
modulo - Returns the remainder after dividing numbers.
round - Rounds output to the nearest integer or specificed number of decimal places.
ceil - Rounds up to the nearest integer.
floor - Rounds down to the nearest integer.
Array Filters:
join - Combines the elements of an array.
first - Returns the first element of an array.
last - Returns the last element of an array.
map - Creates a string from the values of one array element.
size - Returns the size of a string or an array.