To achieve this, you must expand your TwigFilter.
How to write you an extension from the beginning, you can read here .
Assuming you created the extension, you defined your function, say applyFilter.
public function getFunctions()
{
return array(
...
'apply_filter' => new \Twig_Function_Method($this, 'applyFilter'),
);
}
Then you must define this function
public function applyFilter($context, $filterName)
{
}
After these manipulations, you can call Twig:
{{ apply_filter(object, 'filterName') }}
Greetings;)
source
share