The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Using Twig functions inside of Slim

Twig and Slim are a great combination to work with, with Twig's advanced templating parser it allows flexibility when working on projects using it. I have seen questions being asked a few times about how to access Twig related functions inside of Slim.

Twig view class (TwigView or Slim\Extras\Views\Twig) provided in the Slim Extras repository allows us to use Twig as a View for any Slim project. We have kept a copy of the Twig instance inside of the Twig view class (TwigView or Slim\Extras\Views\Twig) to allow you to access Twig easily from inside of Slim. The code below

$twig = $app->view()->getEnvironment();

You now have access to the Twig environment, with this you can call Twig related functions.

$twig->addGlobal('siteName', 'Slim Awesomeness!');

Hope this has been helpful to you.