Filtering Objects
Filters transform an object's output. Objects are surrounded by {{
and }}
.
The descriptions below are taken from the excellent guide Liquid For Designers by Liquid's creators at Shopify.
Standard Filters
append
- append a string e.g.{{ 'foo' | append:'bar' }} #=> 'foobar'
capitalize
- capitalize words in the input sentenceceil
- rounds a number up to the nearest integer, e.g.{{ 4.6 | ceil }} #=> 5
date
- reformat a date (syntax reference)default
- returns the given variable unless it is null or the empty string, when it will return the given value, e.g.{{ undefined_variable | default: "Default value" }} #=> "Default value"
divided_by
- integer division e.g.{{ 10 | divided_by:3 }} #=> 3
downcase
- convert an input string to lowercaseescape_once
- returns an escaped version of html without affecting existing escaped entitiesescape
- html escape a stringfirst
- get the first element of the passed in arrayfloor
- rounds a number down to the nearest integer, e.g.{{ 4.6 | floor }} #=> 4
join
- join elements of the array with certain character between themlast
- get the last element of the passed in arraylstrip
- strips all whitespace from the beginning of a stringmap
- map/collect an array on a given propertyminus
- subtraction e.g.{{ 4 | minus:2 }} #=> 2
modulo
- remainder, e.g.{{ 3 | modulo:2 }} #=> 1
newline_to_br
- replace each newline (\n) with html breakplus
- addition e.g.{{ '1' | plus:'1' }} #=> 2
,{{ 1 | plus:1 }} #=> 2
prepend
- prepend a string e.g.{{ 'bar' | prepend:'foo' }} #=> 'foobar'
remove_first
- remove the first occurrence e.g.{{ 'barbar' | remove_first:'bar' }} #=> 'bar'
remove
- remove each occurrence e.g.{{ 'foobarfoobar' | remove:'foo' }} #=> 'barbar'
replace_first
- replace the first occurrence e.g.{{ 'barbar' | replace_first:'bar','foo' }} #=> 'foobar'
replace
- replace each occurrence e.g.{{ 'foofoo' | replace:'foo','bar' }} #=> 'barbar'
reverse
- reverses the passed in arrayround
- rounds input to the nearest integer or specified number of decimals e.g.{{ 4.5612 | round: 2 }} #=> 4.56
rstrip
- strips all whitespace from the end of a stringsize
- return the size of an array or stringslice
- slice a string. Takes an offset and length, e.g.{{ "hello" | slice: -3, 3 }} #=> llo
sort
- sort elements of the arraysplit
- split a string on a matching pattern e.g.{{ "a~b" | split:"~" }} #=> ['a','b']
strip_html
- strip html from stringstrip_newlines
- strip all newlines (\n) from stringstrip
- strips all whitespace from both ends of the stringtimes
- multiplication e.g{{ 5 | times:4 }} #=> 20
truncate
- truncate a string down to x characters. It also accepts a second parameter that will append to the string e.g.{{ 'foobarfoobar' | truncate: 5, '.' }} #=> 'foob.'
truncatewords
- truncate a string down to x wordsuniq
- removed duplicate elements from an array, optionally using a given property to test for uniquenessupcase
- convert an input string to uppercaseurl_encode
- url encode a string