简体   繁体   English

在twig中嵌套过滤器和函数 Symfony2的

[英]Nesting filters and functions in twig | Symfony2

I have this simple question. 我有这个简单的问题。 Can i nesting filters in twig, using syfmony2? 我可以使用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. “filter1”滤波器输出必须是“filter2”滤波器输入。


Example: 例:

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

{{ getPrice(var)|formatPrize(3,',')|prizeSymbol('u$s') }} prints: u$s 12.251 {{ getPrice(var)|formatPrize(3,',')|prizeSymbol('u$s') }}打印: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. 非常感谢。

Of course filters can be chained, as @Richard wrote. 当然,过滤器可以链接,正如@Richard所写。 For you as the extension author, there is nothing you have to pay attention to. 作为扩展作者,您无需注意。 Your filter code gets input – regardless of whether it's the only filter, or if (for example) it's the 4th filter in a chain of 5 filters. 您的过滤器代码会被输入 - 无论它是唯一的过滤器,还是(例如)它是5个过滤器链中的第4个过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM