I can create a Twig extension for my project like this
class Functions extends Twig_Extension{
public function getName(){return 'foobar';}
public function getFunctions() {
return array(
'loremipsum' => new \Twig_SimpleFunction('asset', 'Functions::loremipsum')
);
public static function loremipsum($foo) {
return $foo;
}
}
this works, but I want to use a constructor to inject some data that I need in some functions.
Simply using 'asset'
in Twig_SimpleFunction
will result in PHP trying to execute the functon loremipsum()
Twig_Function_Method
(as well as allTwig_Function_*
classes) is deprecated. It will be removed in 2.0 – Intussusception