Add globals

v1.0.2
eater 6 years ago
parent 8764acb3bc
commit 3ca6be12d6

@ -3,7 +3,8 @@
"license": "MIT",
"require": {
"twig/twig": "^2.4",
"php-di/php-di": "^5.4"
"php-di/php-di": "^5.4",
"bitcommunism/http": "^1.0"
},
"autoload": {
"psr-4": {

@ -21,6 +21,7 @@ return [
return array_filter($paths, 'is_dir');
}),
'twig.globals' => add([]),
'twig.loader' => get(\Twig_Loader_Filesystem::class),
'twig.debug' => false,
'twig' => get(\Twig_Environment::class),

@ -33,9 +33,14 @@ class Twig extends Handler
$this->templateVariables = array_merge($this->templateVariables, $variables);
}
public function template($template, $variables) {
public function template($template, $variables = [], $useGlobalVariables = true) {
$stream = new TwigStream($this->environment);
$stream->setTemplate($template);
if ($useGlobalVariables) {
$stream->appendVariables($this->container->get('twig.globals'));
}
$stream->appendVariables($this->templateVariables);
$stream->appendVariables($variables);

Loading…
Cancel
Save