Stefano Stefano - 1 month ago 11x
PHP Question

Render template from twig extension

I have built a twig extension to do some things and one of them is render a template. How can I access from inside the twig extension the engine environment and call the Render method?


You can define the extension so that it needs the environment. Twig will automatically pass it to the function.

public function getFunctions()
    return array(
        'myfunction' => new \Twig_SimpleFunction(
            array('needs_environment' => true)

public function myFunction(\Twig_Environment $environment, string $someParam)
    // ...