Commit 0537e441 authored by Fabien Potencier's avatar Fabien Potencier

added a way to post configure Twig (useful to lazy-register Twig extensions for instance)

Usage example:

$app->register(new TwigExtension(), array(
    'twig.path'       => __DIR__.'/templates',
    'twig.options'    => array('cache' => __DIR__.'/../cache', 'debug' => true, 'strict_variables' => true),
    'twig.configure'  => $app->protect(function ($twig) use ($app) {
        $twig->addExtension(...);
    })
));
parent 6d6cb0fd
...@@ -18,6 +18,9 @@ class TwigExtension implements ExtensionInterface ...@@ -18,6 +18,9 @@ class TwigExtension implements ExtensionInterface
$app['twig'] = $app->share(function () use ($app) { $app['twig'] = $app->share(function () use ($app) {
$twig = new \Twig_Environment($app['twig.loader'], $app['twig.options']); $twig = new \Twig_Environment($app['twig.loader'], $app['twig.options']);
$twig->addGlobal('app', $app); $twig->addGlobal('app', $app);
if (isset($app['twig.configure'])) {
$app['twig.configure']($twig);
}
return $twig; return $twig;
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment