Easy access to settings from a Twig View?

Using the Akrabat’s Slim Bookshelf as a basis, is there a way to access values within app/settings.php from a Twig view? I know I can pass it through the action/controller class, but that seems like overkill.

For example, I’m storing public keys for various external services and my views need access to those keys. My actions/controller classes don’t need to know about them, just the Twig views.

The only way I can think of to do it would be to write a simple little Twig Extension. Am I missing another way?

You could add they here(on instatiation) as global vars like:

$view['foo'] = 'bar';

or via Twig Environment:

$twig = $view->getEnvironment();
$twig->addGlobal('foo', 'bar');
1 Like

Eureka! Perfect, thanks so much. :grinning: