Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
addGlobals simplified to help user extend addGlobals
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Jul 24, 2018
1 parent dee5af1 commit 8103386
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
13 changes: 5 additions & 8 deletions src/Twig/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ public static function viewFactory(ContainerInterface $container, array $config)

private function addGlobals() : void
{
// Runtime Config values
$this->twig->addGlobal('RuntimeConfig', $this->config['runtime']['config']);
// Query Parameters ($_REQUEST)
$this->twig->addGlobal('QueryParameters', $this->config['runtime']['query_parameters']??[]);
// Query Parameters ($_SESSION)
$this->twig->addGlobal('Sessions', $this->config['runtime']['session']??[]);
// Query Parameters ($_COOKIES)
$this->twig->addGlobal('Cookies', $this->config['runtime']['cookies']??[]);
if (array_key_exists('runtime', $this->config)) {
foreach ($this->config['runtime'] as $key => $value) {
$this->twig->addGlobal($key, $value);
}
}
}

public function addGlobal(string $name, $value) : void
Expand Down
4 changes: 2 additions & 2 deletions test/TwigTest/templates/main.twig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<html>
<head>
<title>{{ RuntimeConfig.title }}</title>
<title>{{ config.title }}</title>
</head>
<body>
<hr>
App Name : <span id="app_name">{{ app.name }}</span>
<hr>
Query String : <span id="url_param">{{ QueryParameters.param1 }}</span>
Query String : <span id="url_param">{{ query_parameters.param1 }}</span>
<hr>
Add Globals : <span id="add_global">{{ add_global }}</span>
</body>
Expand Down

0 comments on commit 8103386

Please sign in to comment.