Skip to content

Commit

Permalink
[TwigBundle] added request and session as global variables
Browse files Browse the repository at this point in the history
 * removed the "_view" variable from templates
 * removed the "flash()" function (now available from the session directly {{ session.flash('notice') }})
  • Loading branch information
fabpot committed Jan 4, 2011
1 parent 0e487cd commit b60d254
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Bundle/FrameworkBundle/Templating/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function __construct(ContainerInterface $container, LoaderInterface $load
}
}

public function getContainer()
{
return $this->container;
}

/**
* Renders a view and returns a Response.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ public function getFunctions()
'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'),
);
}

Expand All @@ -93,11 +92,6 @@ public function getAssetUrl($location)
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.
*
Expand Down
5 changes: 4 additions & 1 deletion src/Symfony/Bundle/TwigBundle/Renderer/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function __construct(\Twig_Environment $environment)
*/
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);
}
Expand Down

0 comments on commit b60d254

Please sign in to comment.