twig tutorial - Filters in Twig - twig filters - twig php - twig template
Filters
- Variables can be modified using filters. To apply filter to variable follow variable name with pipe | and filter name:
For example to display variable value in uppercase use construct.
Filters can be parametrized. Filter parameters are passed inside parentheses as a comma(,) separated list
- To round number to given precision we can use filter round, it accepts up to 2 parameters. First one specifies precision (default: 0), second one rounding method (default: common).
- To round number to 1 decimal place using common method you can use {{ number|round(1, 'common') }} or {{ number|round(1) }} as common is default method.
Filters can also be used on embedded objects & array variables:
Filters can also be concatenated: