You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Twig.php 992B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Shop\View;
  3. use Twig\Loader\FilesystemLoader;
  4. use Twig\Environment;
  5. class Twig
  6. {
  7. protected $twig;
  8. protected $variables;
  9. public function __construct($tmpl_folder)
  10. {
  11. $loader = new FilesystemLoader($tmpl_folder);
  12. $this->twig = new Environment($loader, []);
  13. $this->variables = [];
  14. }
  15. protected function load($tmpl)
  16. {
  17. return $this->twig->load($tmpl);
  18. }
  19. // add block variables to the global variable bag
  20. // public function addBlockVariable($block, $data)
  21. // {
  22. // $current = $this->variables[$block];
  23. // if ($current) {
  24. // $new = array_merge($current, $data);
  25. // } else {
  26. // $new = $data;
  27. // }
  28. // $this->variables[$block] = $new;
  29. // }
  30. public function render($tmpl, $vars)
  31. {
  32. $template = $this->load($tmpl);
  33. $variables = array_merge($this->variables, $vars);
  34. return $template->render($variables);
  35. }
  36. }