String Filters

Use string filters to manipulate strings.

append: String text
Add text to the end of the current string
capitalize
Capitalize words in a string
classname String separator = "-"
Removes all non-alphanumeric characters other than dashes and underscores from a string and replaces them with the separator (or nothing if the separator is empty).
default: String default_value
If the current value is empty, return the default_value instead. Otherwise return the original value.
downcase
Convert a string to lowercase
escape
Encode a string to be output as HTML. All special HTML characters will be converted to their equivalent HTML character entities (eg: < becomes &lt;)
h
Alias for escape
newline_to_br
Add "<br >" tags in front of all newlines in the current string
plus: string text
Appends the text to the current value. Note that this filter behaves differently if the current value is not a string (eg: {{'Some' | plus:'Thing'}} = 'SomeThing', but {{4 | plus:2}} = 6).
prepend: String text
Add text to the beginning of the current string
remove: String search
Remove all occurrences of search from the current string
remove_first: String search
Remove the first occurrence of search from the current string
replace: String search String replacement = ""
Replace all occurrences of search inside the current string with replacement.
replace_regex: String pattern String replacement = ""
Replace all occurrences of pattern inside the current string with replacement using a regular expression - making it possible to search for more complicated expressions and replace using the resulting matching groups.
replace_first: String search String replacement = "" int numReplacements = 1
Replace the first numReplacements occurrences of search inside the current string with replacement.
replace_regex_first: String pattern String replacement = "" int numReplacements = 1
Replace the first numReplacements occurrences of pattern inside the current string with replacement using a regular expression - similar to the replace_regex filter.
size
Return the size of the current string
slice: int start int len = 0
Return a part of the current string. If start is negative, will return len characters from the end of the string. If len is 0, will return all remaining characters after start. If len is negative, will return up to len characters from the end of the string.
split: String pattern
Split a string into a list of substrings separated by the given pattern
strip
Removes whitespace from the beginning and end of a string
strip_html
Removes all HTML tags from a string
strip_newlines
Removes all newlines from a string
times: int count
Repeats the current value count times. This filter behaves differently if the current value is a string or if count is not an integer (eg: {{'Bon' | times:2}} = 'BonBon', but {{4 | times:2}} = 8).
truncate: int length = 50 String truncate_string = "..."
Truncates a string down to length characters. If the original string is longer than length characters, appends truncate_string to the end of the truncated string.
truncate_words: int length = 50 String truncate_string = "..."
Truncates a string down to length words. If the original string is longer than length words, appends truncate_string to the end of the truncated string.
upcase
Convert a string to uppercase
url_decode: boolean formData = false
Decode a UrlEncoded string. If formData is true, decodes the string as if it were submitted as part of an html form (eg: decodes the + character to a space character). If formData is false, decodes the string as a normal url_encoded string (eg: leaves the + character alone).
url_encode boolean formData = false
Encode a string to be used in a URL. If formData is true, encodes the string as if it were submitted as part of an html form (eg: encodes the space character to the + character). If formData is false, encodes the string as a normal url string (eg: encodes the space character as %20).

Developer Overview

Liquid Markup