TwigBridge icon indicating copy to clipboard operation
TwigBridge copied to clipboard

twig.php globals - not fully global?

Open johannes-z opened this issue 11 years ago • 3 comments

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.

johannes-z avatar Oct 26 '14 23:10 johannes-z

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.

barryvdh avatar Oct 29 '14 10:10 barryvdh

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.

johannes-z avatar Oct 29 '14 15:10 johannes-z

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.

barryvdh avatar Oct 29 '14 15:10 barryvdh