I see you're overwriting $app["twig"]
entirely instead of using the one created by TwigServiceProvider. Note that it registers the app
global (link) that you'll need to do yourself on your Twig_Environment
instance.
Silex Twig app.request global not working
Question
I am currently working with Silex and Twig, and I am encountering an issue where the
{{ app.request }}
call does not return anything.
Here is my twig configuration
'twig' => $application->share($application->extend('twig', function (Twig_Environment $twig, Application $application) {
$loader = new Twig_Loader_Filesystem(__DIR__ . '/../../src/quest/view');
$twig = new Twig_Environment($loader);
$host = $application['request']->getSchemeAndHttpHost();
$path = $application['request']->getPathInfo();
$twig->addGlobal('RESOURCE', '/web/res');
$twig->addGlobal('HOST', $host);
$twig->addGlobal('PATH', $path);
return $twig;
}))
My variable is named 'application' instead of 'app', but I also tried
{{ app.request.host }}
{{ application.request.host }}
and neither of them worked.
Solution
OTHER TIPS
This may happen when you use render other controller.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow