Templates

Filters

A filter is a method that takes one or more parameters and returns a value. Parameters are passed to filters by position: the first parameter is the expression preceding the pipe character, and additional parameters can be passed using the name: arg1, arg2 syntax described above.

Text Filters
Name Description
Append append a string e.g. {{ 'foo' | Append:'bar' }} #=> 'foobar'
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"
Downcase convert an input string to lowercase
DowncaseFirst convert the first letter to lowercase
ExtractValue extract the value from the parenthesis
e.g. {{ varchar(50) | ExtractValue }} #=> 50
e.g. {{ decimal(10,2) | ExtractValue }} #=> 10,2
Lstrip strips all whitespace from the beginning of a string
Prepend prepend a string e.g. {{ 'bar' | Prepend:'foo' }} #=> 'foobar'
Pluralized convert a word in plural form e.g. {{ 'category' | Pluralized }} #=> 'categories'
RemoveFirst remove the first occurrence e.g. {{ 'barbar' | RemoveFirst:'bar' }} #=> 'bar'
RemoveLast remove the last occurrence e.g. {{ 'CategoryId' | RemoveLast:'Id' }} #=> 'Category'
Remove remove each occurrence e.g. {{ 'foobarfoobar' | Remove:'foo' }} #=> 'barbar
ReplaceFirst replace the first occurrence e.g. {{ 'barbar' | ReplaceFirst:'bar','foo' }} #=> 'foobar'
Replace replace each occurrence e.g. {{ 'foofoo' | Replace:'foo','bar' }} #=> 'barbar'
Rstrip strips all whitespace from the end of a string
SeparateWords insert a separator between the words, e.g. {{ 'InStock' | SeparateWords: ' ' }} #=> In Stock
Slice slice a string. Takes an offset and length, e.g. {{ "hello" | Slice: -3, 3 }} #=> llo
Split split a string on a matching pattern e.g. {{ "a~b" | Split:"~" }} #=> ['a','b']
StripNewlines strip all newlines (\n) from string
Strip Strips all whitespace from both ends of the string
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 words
Uniq removed duplicate elements from an array, optionally using a given property to test for uniqueness
Upcase convert an input string to uppercase
Math Filters
Name Description
Ceil rounds a number up to the nearest integer, e.g. {{ 4.6 | Ceil }} #=> 5
DividedBy integer division e.g. {{ 10 | DividedBy:3 }} #=> 3
Floor rounds a number down to the nearest integer, e.g. {{ 4.6 | Floor }} #=> 4
Minus subtraction e.g. {{ 4 | Minus:2 }} #=> 2
Modulo remainder, e.g. {{ 3 | Modulo:2 }} #=> 1
Plus addition e.g. {{ '1' | plus:'1' }} #=> 2 , {{ 1 | Plus:1 }} #=> 2
Round rounds input to the nearest integer or specified number of decimals e.g. {{ 4.5612 | Round: 2 }} #=> 4.56
Times multiplication e.g {{ 5 | Times:4 }} #=> 20
Array Filters
Name Description
First get the first element of the passed in array
Join join elements of the array with certain character between them
Last get the last element of the passed in array
Size return the size of an array or string
Sort sort elements of the array
Reverse reverses the passed in array
Html Filters
Name Description
EscapeOnce returns an escaped version of html without affecting existing escaped entities
NewlineToBr replace each newline (\n) with html break
StripHtml strip html from string
UrlEncode url encode a string
© DynamoCode.