2013-08-28 60 views
1

我有枝杈濾波器定義如下:傳遞陣列來篩選枝條

'namefilter' => new \Twig_Filter_Method ($this, 'myFilter') 

和功能的這樣的頭:

public function myFilter ($text, $array = array('defect')) 

如何從樹枝調用到過濾器。 如何創建一個樹枝數組將其傳遞給過濾器?

問候和謝謝。

回答

1
{{ 'text'|namefilter(['notdefect']) }} 

或者:

{% set arr = ['notdefect'] %} 
{{ 'text'|namefilter(arr) }} 

注:應使用Twig_SimpleFilter,而不是Twig_Filter_Method它被廢棄,將在2.0版本中完全刪除:

new \Twig_SimpleFilter('namefilter', 'myFilter'); 
+0

感謝您回答。 – Bicu

+0

不客氣@Bicu – Paulpro

0
{{ 'text'|nameFilter(['defect']) }}