Edit
Lang

Default Latte Filters

Filters are functions which change or format the data to a form we want. This is summary of the default filters which are normally available.

All default filters work with UTF-8 encoded strings.

String modification
truncate (length, append = '…') shortens the length preserving whole words
substr (offset [, length]) returns part of the string
trim (charset = whitespace) strips whitespace or other characters from the beginning and end of the string
striptags removes HTML tags
strip removes whitespace
indent (level = 1, char = "\t") indents the text from left with number of tabs
replace (search, replace = '') replaces all occurrences of the search string with the replacement
replaceRE (pattern, replace = '') replaces all occurrences according to regular expression
padLeft (length, pad = ' ') completes the string to given length from left
padRight (length, pad = ' ') completes the string to given length from right
repeat (count) repeats the string
implode (glue = '') joins an array to a string
breaklines Inserts HTML line breaks before all newlines
Letter casing
lower makes a string lower case
upper makes a string upper case
firstUpper makes the first letter upper case
capitalize lower case, the first letter of each word upper case
Formatting
date (format) formats date
number (decimals = 0, decPoint = '.') format number
bytes (precision = 2) formats size in bytes
Other
noescape prints a variable without escaping
dataStream (mimetype = detect) Data URI protocol conversion
escapeurl escapes parameter in URL
checkurl sanitizes string for use inside href attribute
nocheck removes use of checkurl filter
length returns length of a string

Truncate

Shortens a string to the maximum given length but tries to preserve whole words. If the string is truncated it adds ellipsis at the end (this can be changed by the second parameter).

{var $title = 'Hello, how are you?'}
{$title|truncate:5} Hell…
{$title|truncate:17} Hello, how are…
{$title|truncate:30} Hello, how are you?

Strip

Removes unnecessary whitespace from the output.

{block |strip}
    <ul>
        <li>Hello</li>
    </ul>
{/block}

Generates

<ul> <li>Hello</li> </ul>

Indent

Indents a text from left by a given number of tabs or other characters which we specify in the second optional argument:

<div>
{block |indent}
<p>Hello</p>
{/block}
</div>

Generates

<div>
    <p>Hello</p>
</div>

Breaklines

Inserts HTML line breaks before all newlines. Input text is automatically escaped.

{var $s = "Text & with \n newline"}
{$s|breaklines} "Text &amp; with <br>\n newline"

Letter casing

{var $s = 'blue COLOR'}
{$s|lower} blue color
{$s|upper} BLUE COLOR
{$s|firstUpper} Blue COLOR
{$s|capitalize} Blue Color

Date

Returns a date in the given format using options of strftime or date PHP functions. Filter gets a date as a UNIX timestamp, a string or an object of DateTime type.

{$today|date:'%d.%m.%Y'}

Number

Formats a number to given number of decimal places. You can also specify a character of the decimal point and thousands separator.

{1234.20 |number}  1,234
{1234.20 |number:1}  1,234.2
{1234.20 |number:2}  1,234.20
{1234.20 |number:2:',':' '}  1 234,20

Bytes

Formats a size in bytes to human-readable form.

{$size|bytes} 0 B, 10 B or 1.25 GB, …

DataStream

Converts the data to URI scheme. With this filter you can insert images to HTML or CSS without linking external files. All the modern browsers. Requires PHP extension fileinfo.

Lets have an image in a variable $img = Image::fromFile('obrazek.gif'), then

<img src="{$img|dataStream}">

generates for example:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
9TXL0Y4OHwAAAABJRU5ErkJggg==">

EscapeUrl

Escapes a variable to be used as a parameter in URL.

<a href="http://example.com/{$name|escapeurl}">{$name}</a>