1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
-
- namespace Shop\View;
-
- use Twig\Loader\FilesystemLoader;
- use Twig\Environment;
-
- class Twig
- {
-
- protected $twig;
- protected $variables;
-
- public function __construct($tmpl_folder)
- {
- $loader = new FilesystemLoader($tmpl_folder);
- $this->twig = new Environment($loader, []);
- $this->variables = [];
- }
-
- protected function load($tmpl)
- {
- return $this->twig->load($tmpl);
- }
-
- // add block variables to the global variable bag
- // public function addBlockVariable($block, $data)
- // {
- // $current = $this->variables[$block];
- // if ($current) {
- // $new = array_merge($current, $data);
- // } else {
- // $new = $data;
- // }
- // $this->variables[$block] = $new;
- // }
-
- public function render($tmpl, $vars)
- {
- $template = $this->load($tmpl);
- $variables = array_merge($this->variables, $vars);
- return $template->render($variables);
- }
- }
|