Filters
Filters are a method of modifying the output of numbers, strings, variables and objects. They're placed within an output tag {{ }} and are denoted with the pipe | character appended to the attribute.
{{ product.title|upper }}
returns...
WHITE NIKE AIR MAX TRAINERS
In the above example the title attribute of the product object has been modified to return capitalised.
More than one filter can be used on the same output.
Available filters
The following filters are available:
capitalize
The capitalize filter capitalises the first letter of a value.
first
The first filter returns the first element of a sequence.
{{ product.tite|first }}
returns...
N
join
The
join filter returns a string which is the concatenation of the items of a sequence. Read more about the join filter here.
last
The last filter returns the last element in a sequence. It is the obverse of the first filter (described above).
length
The length filter returns the number of items in a sequence or mapping or the length of a string.
lower
The lower filter converts a value to lowercase.
{{ product.title|lower }}
returns...
white nike air max trainers
number_format
The number_format filter formats numbers. It's a wrapper around php's number format function.
raw
The
raw filter marks the value as being "safe", which means that in our platform, the variable will not be escaped if raw is the last filter applied to it.
striptags
The striptags filter strips SGML/XML tags from a string.
title
The
title filter returns a titlecased version of the value. Words will start with uppercase letters, all remaining characters in a word are lowercase.
truncate
The truncate filter will truncate a string to a defined number of characters. You can also mark the filter with true to ensure that whole words are not trimmed.
{{ product.title|truncate(15, true) }}
returns...
White nike air...
When used, by default it will append ... to the end of the string. You can mark the filter with false to prevent this, e.g. {{ product.title|truncate(15, true, false) }}
You can override the default separator of ... , e.g. {{ product.title|truncate(15, true, '.........') }}
upper
The upper filter converts a value to uppercase. It is the obverse of the lower filter.
nl2br
The nl2br filter inserts HTML line breaks before all new lines in a string.
replace
The replace filter will replace a string with another string. It can be used to remove part of a string (by replacing with nothing) or to replace one word with another.
{{ product.title|replace({'nike': ''}) }}
returns...
White air max trainers
Whereas...
{{ product.title|replace({'nike': 'adidas'}) }}
returns...
White adidas air max trainers