phpsymfonytwigsymfony-2.4

Nesting filters and functions in twig | Symfony2


I have this simple question. Can i nesting filters in twig, using syfmony2?

Imagine i need to do the following in twig:

{{ custom_function(var)|filter1|filter2 }}

Also i need respect the order. The "filter1" filter output, has to be the "filter2" filter input.


Example:

{{ getPrice(var)|formatPrize(2,'.')|prizeSymbol('$') }} prints: $ 12.25

{{ getPrice(var)|formatPrize(3,',')|prizeSymbol('u$s') }} prints: u$s 12.251


The above requirement is useless, but i need to do something like this.

I know how to make the twig extension, but not how to solve nesting.

I apologize for my english, Google Translate did the hard work :-)

Thanks a lot.


Solution

  • Filters can be chained as per the documentation

    E.g.

    {{ name|striptags|title }}