Slim 4 twig globals

I actually no longer think this is a logic error. I have been slammed at work and haven’t been able to investigate as much as I wish, but soon I think I can post with a definitive answer about using Globals with Slim’s TwigView.

Basically, you must instantiate an instance of Twig, then add the globals BEFORE adding to the container and adding TwigView middleware to the app. You have to add the globals, even if they’re initialized to NULL. So long as they’ve been added, you can change them later by using addGlobal(). That’s what the validator is checking in the code that I originally posted. If you’ve already started the middleware, but the global DOESN’T exist, then the exception is thrown.

1 Like