Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Environment.php

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

Twig

Code

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;
    }
}
RSS feed
Powered by Drupal