String Filters

String Filters

append filter

Add text to the end of the input. If the input is not already a string it will be converted to one using the default behavior for its object type.

append: String text

Examples

Append text onto the end of a string

Append text

Copy
{{"fire" | append:"truck"}}
firetruck

Related

capitalize filter

Capitalize words in a string

capitalize

Examples

Capitalize all of the words in a sentance

Capitalize words in a string

Copy
{{"a freight train running through the" | capitalize}}
A Freight Train Running Through The

Related

classname filter

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) to form a valid CSS classname.

classname: String separator

Related

downcase filter

Convert a string to lowercase

downcase

Related

escape filter

Encode a string to be output as HTML. All special HTML characters will be converted to their equivalent HTML character entities (eg: < becomes <)

escape

Related

escape_once filter

Encode a string to be output as HTML, without changing existing escaped entities.

escape_once

Related

DEPRECATED for_json filter

This filter has been deprecated. You should use the json_encode filter instead. Encode a string to be used output as JSON. Unlike json_encode, if the string is null this will return an empty string instead.

for_json

Related

{% for %}

Iterates through every item in a list. Executes and outputs a block of code to the template for each item in the list.

h filter (alias for escape)

Alias for escape, which encodes a string to be output as HTML. Although "h" is shorter, "escape" is preferred due to its improved readability and maintainability.

h

Related

html_decode filter

Decodes any encoded HTML entities (eg: < becomes <)

html_decode

Related

{{ html }}

html_encode filter

Encode a string to be output as HTML. All special HTML characters will be converted to their equivalent HTML character entities (eg: < becomes <). This is functionally identical to the "escape" filter, though it may be more intuitive in some contexts - such as when using both the html_encode and html_decode filters to execute more advanced string manipulation.

html_encode

Related

{{ html }}

index filter

Returns the 0-based location of the find string in the current string, or -1 if it cannot be found. If start is greater than 0, the search will begin at the specified index. To ignore capitalization, set ignorecase to true.

index: String findInteger startBoolean ignorecase

Related

json_decode filter

Decode a json encoded string

json_decode

Related

json_encode filter

Encode the input object to be used as a JSON property.

json_encode

Null values output the string "null". Dates are output using the ISO 8601 standard. Booleans are output as "true" or "false". Numbers are output as numbers. Strings are output as json encoded strings with quote marks properly escaped.

Related

last_index filter

Returns the last 0-based location of the last occurrence of find string in the current string, or -1 if it cannot be found. If start is greater than or equal to 0, the search will begin at the specified index. To ignore capitalization, set ignorecase to true.

last_index: String findInteger startBoolean ignorecase

Related

lstrip filter

Removes whitespace from the beginning of a string

lstrip

Related

newline_to_br filter

Add <br /> tags in front of all newlines in the current string

newline_to_br

Related

plus filter

Adds the operand to the current value. Note that this filter behaves differently if the current value is a string

plus: Number operand

The plus filter may behave differently when used with string input. When used with a string input it may append text to the current value, although that behavior is deprecated and should be replaced by the append filter for optimal forward-compatibility.

Related

prepend filter

Add text to the beginning of the input. If the input is not already a string it will be converted to one using the default behavior for its object type.

prepend: String text

Related

remove filter

Remove all occurrences of search from the current string.

remove: String search

Related

remove_first filter

Remove the first occurrence(s) of search from the current string.

remove_first: String searchInteger num_replacements

Related

replace filter

Replace all occurrences of search inside the current string with replacement

replace: String searchString replacement

Related

replace_first filter

Replace the first occurrence(s) of search inside the current string with replacement

replace_first: String searchString replacementInteger num_replacements

Related

replace_regex filter

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 captured groups.

replace_regex: String patternString replacement

Related

replace_regex_first filter

Replace the first occurrence(s) 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 captured groups.

replace_regex_first: String patternString replacementInteger num_replacements

Related

reverse filter

Reverses the input string or list.

reverse

When used with a string as input, the result is a string. Otherwise the result is a list.

Related

rstrip filter

Removes whitespace from the end of a string

rstrip

Related

size filter

Returns the length of the input string or list.

size

If the input is not a string or list returns 0.

Related

slice filter

Return a part of the current string or list.

slice: Integer startInteger length

If the input is a string this will return a string. If it is a list it will return a list. Otherwise it will not do anything and will return the unaltered input.

Related

split filter

Split a string into a list of substrings separated by the given separator

split: String separator

Related

strip filter

Removes whitespace from the beginning and end of a string

strip

Related

strip_html filter

Removes all HTML tags from a string

strip_html

This filter uses simple pattern matching to remove HTML tags. If the input is poorly formatted or contains unusual character sequences - particularly involving the '<' and '>' characters - this could result in unexpected behavior.

Related

{{ html }}

strip_newlines filter

Removes all newlines from a string

strip_newlines

Related

times filter

Multiply the input by the operand.

times: Number operand

This filter currently behaves differently if the input is a string and the operand is an integer. In that case the result is a list of strings with input repeated operand times.

Related

{{ time }}

Represents a specific instant in a specific timezone.

truncate filter

Truncates a string down to length characters. If the original string is longer than length characters, the result will end with truncate_string.

truncate: Integer lengthString truncate_string

Related

truncate_to_word filter

Truncates a string down to length characters. If the string would be broken in the middle of a word, ensures that the break happens either before or after the word. If the string is truncated it will end with truncate_string.

truncate_to_word: Integer lengthBoolean break_before_wordString truncate_string

The truncate_to_word uses a naive algorithm for word counting that considers words as one or more letters, digits, underscores, or apostrophes. All other characters are considered non-word characters in between words. This means that a string could still be truncated in the middle of a hypenated word or a word with other non-word characters such as "awe-inspiring", "r&r", "1.25", "3/4", etc.... This filter also does not strip or consolidate whitespace, or handle HTML markup any different than normal text.

Related

truncate_words filter

Truncates the input string down to length words. If the input is longer than length words, appends truncate_string to the end of the truncated string.

truncate_words: Integer lengthString truncate_string

The truncate_words uses a naive algorithm for word counting that considers words as one or more letters, digits, underscores, or apostrophes. All other characters are considered non-word characters in between words. This means that hyphenated words such as "awe-inspiring" are counted as two words, as are "words" with other characters between letters, such as "r&r", "1.25", "3/4", etc.... This filter also does not strip or consolidate whitespace, or handle HTML markup any different than normal text.

Related

upcase filter

Convert a string to uppercase

upcase

Related

url_decode filter

Decode a url encoded string.

url_decode: Boolean formdata

Related

{% image_url %}

Resolves the URL for an image with the desired presets and other settings applied.

{{ url }}

Field containing a URL.

{% set_canonical_url %}

Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.

url_encode filter

Encode a string to be used in a URL.

url_encode: Boolean formdata

Related

{% image_url %}

Resolves the URL for an image with the desired presets and other settings applied.

{{ url }}

Field containing a URL.

{% set_canonical_url %}

Sets the canonical URL for the current page, which is output by default as part of an HTML page's {{ automatic_markup }}.