function 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
mixed $value The global value:
File
-
vendor/
twig/ twig/ src/ Environment.php, line 818
Class
- Environment
- Stores the Twig configuration and renders templates.
Namespace
TwigCode
public function addGlobal(string $name, $value) {
if ($this->extensionSet
->isInitialized() && !\array_key_exists($name, $this->getGlobals())) {
throw new \LogicException(\sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name));
}
if (null !== $this->resolvedGlobals) {
$this->resolvedGlobals[$name] = $value;
}
else {
$this->globals[$name] = $value;
}
}