public function Twig_Environment::addGlobal in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/twig/twig/lib/Twig/Environment.php \Twig_Environment::addGlobal()
Registers a Global.
New globals can be added before compiling or rendering a template; but after, you can only update existing globals.
Parameters
string $name The global name:
mixed $value The global value:
File
- vendor/
twig/ twig/ lib/ Twig/ Environment.php, line 1166
Class
- Twig_Environment
- Stores the Twig configuration.
Code
public function addGlobal($name, $value) {
if ($this->extensionInitialized || $this->runtimeInitialized) {
if (null === $this->globals) {
$this->globals = $this
->initGlobals();
}
if (!array_key_exists($name, $this->globals)) {
// The deprecation notice must be turned into the following exception in Twig 2.0
@trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated.', $name), E_USER_DEPRECATED);
//throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name));
}
}
if ($this->extensionInitialized || $this->runtimeInitialized) {
// update the value
$this->globals[$name] = $value;
}
else {
$this->staging
->addGlobal($name, $value);
}
}