Skip to content

Instantly share code, notes, and snippets.

@zdenekdrahos
Last active May 16, 2022 19:53
Show Gist options
  • Save zdenekdrahos/981ad84a3d1a86b31ec4 to your computer and use it in GitHub Desktop.
Save zdenekdrahos/981ad84a3d1a86b31ec4 to your computer and use it in GitHub Desktop.
Nette - global variables in Latte (https://quip.com/1DAjAVxx9gZ8)
// app/config/config.neon
parameters:
globals:
appVersion: v1.0.0
services:
nette.latteFactory:
class: App\LatteWithGlobalVariables
setup:
- addGlobals(%globals%)
<?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