Looking at the Request object , I found a possible solution.
The controller is attached to the object Request, so it can be retrieved in Twig from the line:
app.request.attributes.get('_controller')
and so get the package name. For example, you can define such a filter function through TwigExtension , for example
public function getFilters() {
return array(
...
'bundleName'=>new \Twig_Filter_Method($this, 'bundleNameFilter'),
);
}
public static function bundleNameFilter($string){
return strstr(substr(strstr($string, '\\'), 1), '\\', true);
}
Then in the branch use it like this:
{{ app.request.attributes.get('_controller') | bundleName }}
Hope this helps.