Last active
May 16, 2022 19:53
-
-
Save zdenekdrahos/981ad84a3d1a86b31ec4 to your computer and use it in GitHub Desktop.
Nette - global variables in Latte (https://quip.com/1DAjAVxx9gZ8)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app/config/config.neon | |
parameters: | |
globals: | |
appVersion: v1.0.0 | |
services: | |
nette.latteFactory: | |
class: App\LatteWithGlobalVariables | |
setup: | |
- addGlobals(%globals%) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use Latte\Engine; | |
class LatteWithGlobalVariables extends Engine | |
{ | |
private $globals = []; | |
public function addGlobals(array $globals) | |
{ | |
$this->globals = $globals; | |
} | |
public function render($name, array $params = array()) | |
{ | |
return parent::render($name, $params + $this->globals); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment