[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') }})
This commit is contained in:
parent
0e487cdda6
commit
b60d254be2
@ -52,6 +52,11 @@ class Engine extends BaseEngine
|
||||
}
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a view and returns a Response.
|
||||
*
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user