From b60d254be2f9b9a8b1340a8f7b40270748692ca5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 4 Jan 2011 13:59:16 +0100 Subject: [PATCH] [TwigBundle] added request and session as global variables * removed the "_view" variable from templates * removed the "flash()" function (now available from the session directly {{ session.flash('notice') }}) --- src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php | 5 +++++ .../Bundle/TwigBundle/Extension/TemplatingExtension.php | 6 ------ src/Symfony/Bundle/TwigBundle/Renderer/Renderer.php | 5 ++++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php index fba43a16f8..a507ff1907 100755 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php @@ -52,6 +52,11 @@ class Engine extends BaseEngine } } + public function getContainer() + { + return $this->container; + } + /** * Renders a view and returns a Response. * diff --git a/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php b/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php index 6243d864e3..c3f9144b0d 100644 --- a/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php +++ b/src/Symfony/Bundle/TwigBundle/Extension/TemplatingExtension.php @@ -74,7 +74,6 @@ class TemplatingExtension extends \Twig_Extension 'url' => new \Twig_Function_Method($this, 'getUrl'), 'path' => new \Twig_Function_Method($this, 'getPath'), 'asset' => new \Twig_Function_Method($this, 'getAssetUrl'), - 'flash' => new \Twig_Function_Method($this, 'getFlash'), ); } @@ -93,11 +92,6 @@ class TemplatingExtension extends \Twig_Extension return $this->container->get('templating.helper.assets')->getUrl($location); } - public function getFlash($name, $default = null) - { - return $this->container->get('request')->getSession()->getFlash($name, $default); - } - /** * Returns the token parser instance to add to the existing list. * diff --git a/src/Symfony/Bundle/TwigBundle/Renderer/Renderer.php b/src/Symfony/Bundle/TwigBundle/Renderer/Renderer.php index 459fa47b2c..0316bfafd4 100644 --- a/src/Symfony/Bundle/TwigBundle/Renderer/Renderer.php +++ b/src/Symfony/Bundle/TwigBundle/Renderer/Renderer.php @@ -37,7 +37,10 @@ class Renderer extends BaseRenderer */ public function evaluate(Storage $template, array $parameters = array()) { - $parameters['_view'] = $this->engine; + // cannot be set in the constructor as we need the current request + $request = $this->engine->getContainer()->get('request'); + $this->environment->addGlobal('request', $request); + $this->environment->addGlobal('session', $request->getSession()); return $this->environment->loadTemplate($template)->render($parameters); }