Variables can be modified by filters. Filters are separated from the variable name by a pipe symbol |
. Multiple filters can be chained. The output of one filter is applied to the next.
The following example removes all HTML tags from the name and title-cases it:
twig
{{ name |title }}
Filters that accept arguments have parentheses around the arguments. This example joins the elements of a list with commas:
twig
{{ list | join(', ') }}
To apply a filter on a section of code, wrap it with the filter
tag:
twig
{% filter lower | title %}
hello<br>
{% endfilter %}}
List of built-in filters:
- abbreviate
- abs
- base64decode
- base64encode
- capitalize
- chunk
- className
- date
- dateAdd
- default
- first
- join
- jq
- json
- keys
- last
- length
- lower
- merge
- number
- numberformat
- replace
- reverse
- rsort
- sha256
- slice
- slugify
- sort
- split
- substringAfter
- substringAfterLast
- substringBefore
- substringBeforeLast
- timestamp
- timestampMicro
- timestampNano
- title
- trim
- upper
- urlencode