Show/Hide Toolbars

Output markup takes filters. Filters are simple methods. The first parameter is always the output of the left side of the filter. The return value of the filter will be the new left value when the next filter is run. When there are no more filters, the template will receive the resulting string. Listing 1 shows some example of using filters in markup expressions.

Filter names are case sensitive (all filter names are lower case). Some filters take arguments, arguments are added after the filter name separated by colon. Multiple arguments are separated by a comma.

Hello {{ 'tobi' | upcase }}

Hello tobi has {{ 'tobi' | size }} letters!

Hello {{ 'now' | cdate: "%Y %h" }}

Listing 1: Markup expressions using filters

Filters

Filter

Notes

append

Append a string e.g. {{ 'foo' | append:'bar' }} results in foobar

capitalize

Capitalize words in the input sentence

cdate:<formatstring>,<cultureName>

Reformat a date. formatstring is a date format string, culture name is any valid culture name E.g. en-US . If culture name is left empty the User's Application server culture will be used.

{{ SomeDateVariable | cdate:"MMMM dd, yyyy", "en-US" }}

cnumber:<formatstring>,<cultureName>

Reformat a numeric value. formatstring is a numeric format string, culture name is any valid culture name E.g. en-US . If culture name is left empty the User's Application server culture will be used.

{{ SomeNumericVariable | cnumber:"e", "en-US" }}

divided_by

Division e.g. {{ 10 | divided_by:2 }} results in 5

downcase

Convert an input string to lowercase

escape

Escape a string

escape_once

Returns an escaped version of html without affecting existing escaped entities

first

Get the first element of the passed in array

getvalidfilename

Replaces characters in a string that are not valid characters for files and directories in a windows file system. If a replacement character is passed and if that character is a valid character for files an directories this replacement is used else then underscore character is used as replacement.

getwordno: <delimiter>, <number>

Gets a specific word from a string.

Eg:

{{ 'foo1 bar1 foo2 bar2' | getwordno: ' ', 1 }} results in bar1 (note: word number is given 0-based)

last

Get the last element of the passed in array

map

Map/collect an array on a given property

minus

Subtraction e.g. {{ 4 | minus:2 }} results in 2

modulo

Remainder, e.g. {{ 3 | modulo:2 }}  results in 1

newline_to_br

Replace each newline (\n) with html break

padleft

Returns a string from an expression, padded with spaces or characters to a specified length on the left side.

e.g. {{ 'abc' | padleft:'X', 5}} returns XXabc

{{ '123' | padleft: '0', 5}} returns 00123

{{ '123' | padleft: '0', 2}} returns 123

Padleft works with strings as well as with numbers. If the padding character is not given a space will be used, if the length is not given a length of 1 is assumed.

plus

Addition e.g. {{ '1' | plus:'1' }} results in '11', {{ 1 | plus:1 }} results in 2

prepend

Prepend a string e.g. {{ 'bar' | prepend:'foo' }} results in foobar

remove

Remove each occurrence e.g. {{ 'foobarfoobar' | remove:'foo' }} results in barbar

remove_first

Remove the first occurrence e.g. {{ 'barbar' | remove_first:'bar' }} results in bar

replace

Replace each occurrence e.g. {{ 'foofoo' | replace:'foo','bar' }} results in barbar

replace_first

Replace the first occurrence e.g. {{ 'barbar' | replace_first:'bar','foo' }} results in foobar

size

Return the size of an array or string

sort

Sort elements of the array

split

Split a string on a matching pattern e.g. {{ "a~b" | split:"~" }}  results in ['a','b']

strip_html

Strip html from string

strip_newlines

Strip all newlines (\n) from string

times

Multiplication e.g {{ 5 | times:4 }} results in 20

truncate:<maxLength>

Truncate a string down to maxLength characters. If the text is longer than the given number of characters the text is truncated and an ellipsis is added to the end of the string.

E.g. {{ 'AVeryLongFileName' | truncate: 8}} results in AVery...

truncatebeginningend: <beginning>, <end>

Truncates the given number of characters from the beginning of a string and then the given number of characters from the end of the string and returns the result.

E.g. {{ '40_000982_01' | truncatebeginningend: 3, 3}} results in 000982

truncatewords:<maxWords>

Truncate a string down to maxWords words

upcase

Convert an input string to uppercase

Table 2: Available filters

© 2021 AFRY Austria GmbH, www.redbex.com