Twig::addGlobal PHP Method

addGlobal() public method

Registers a Global
public addGlobal ( string $name, mixed $value )
$name string The global name
$value mixed The global value
    public function addGlobal($name, $value)
    {
        $this->createTwig();
        $this->twig->addGlobal($name, $value);
    }

Usage Example

 public function testAddGlobal()
 {
     $obj = new Twig(['paths' => __DIR__ . '/../templates/']);
     $obj->addGlobal('sitename', 'Twig Test Site');
     $output = $obj->render('global');
     $this->assertEquals('<title>Twig Test Site</title>' . "\n", $output);
 }
All Usage Examples Of Twig::addGlobal