TIL: PHP - Twig needs_environment need env as first parameter

PHP Twig function configuration

If there is ‘needs_environment’ option in twig function definition you’ll need to pass Twig_Environment as first parameter to your mapped twig function

new \Twig_Function_Method(
    $this,
    'some',
    [
        'needs_environment' => true,
    ]
)


function some(Twig_Environment $env, $otherParams) {
    return "";
}
comments powered by Disqus