TwigBridge
TwigBridge copied to clipboard
twig.php globals - not fully global?
Adding key-value pairs to twig.php in /app/config/packages/rcrowe/twigbridge/twig.php.
'globals' => [
'controller' => Request::segment(1)
],
In some controllers & actions the variable has a value, in another action the variable is NULL. Adding globals via
Twig::addGlobal($key, $value);
does work however. But where do I put it? I put it to the end of /app/start/global.php.
Could you create an example to show when this fails? I did a quick test and a value set in the config does appear in my views, both in the called view as the extended template.
Ok I just did some testing: This occurred because I was using Twig::render instead of View::make in the controller's action, which rendered the view just fine, but didn't include the globally defined variables.
Okay the global data is indeed passed to the Engine/Twig, used for View::make(), not for Twig::render(). I'll see if I can change it so just add the globals to Twig, not sure why we changed that.