getTemplateDir()]); $this->environment = new Environment($loader); $this->kernel = $kernel; $this->addFunctions(); } public function render(string $template, array $vars = []): string { return $this->environment->render($template, $vars); } public function addFunctions() { $path = new TwigFunction('path', function(string $route) { return $this->kernel->getRouter()->getUrlForRoute($route); }); $this->environment->addFunction($path); } }