Ruben De Baets 2 роки тому
джерело
коміт
eb399f5c73
1 змінених файлів з 8 додано та 4 видалено
  1. 8
    4
      src/View/Twig.php

+ 8
- 4
src/View/Twig.php Переглянути файл

@@ -15,6 +15,7 @@ class Twig
{
$loader = new FilesystemLoader($tmpl_folder);
$this->twig = new Environment($loader, []);
$this->variables = ['navbar' => [], 'messages' => [], 'footer' => []];
}

protected function load($tmpl)
@@ -22,15 +23,18 @@ class Twig
return $this->twig->load($tmpl);
}

public function addToVar($data)
// add block variables to the global variable bag
public function addBlockVariable($block, $data)
{
// TODO: Add data to variables
//$this->variables = $data +
$current = $this->variables[$block];
$new = array_merge($current, $data);
$this->variables[$block] = $new;
}

public function render($tmpl, $vars)
{
$template = $this->load($tmpl);
$variables = $vars; // TODO: add global variables
$variables = array_merge($this->variables, $vars);
return $template->render($variables);
}
}

Завантаження…
Відмінити
Зберегти