Beispiel #1
0
 /**
  * Renders a view
  *
  * @param string $template The template name
  *
  * @return string
  */
 public function render($template)
 {
     $debug = defined('WP_DEBUG') ? WP_DEBUG : false;
     if (is_writable('/tmp')) {
         if (!is_dir(self::CACHE_DIR)) {
             mkdir(self::CACHE_DIR);
         }
         $cache = self::CACHE_DIR;
     } else {
         $cache = null;
     }
     Twig_Autoloader::register();
     $loader = new Twig_Loader_Filesystem([$this->paths->getThemeViewsDir(), $this->paths->getBaseViewsDir()]);
     $twig = new Twig_Environment($loader, ['auto_reload' => $debug, 'cache' => $cache, 'charset' => 'UTF-8', 'debug' => $debug, 'strict_variables' => $debug]);
     $view = $twig->loadTemplate(sprintf('%s.html.twig', $template));
     return $view->render(['view' => new ViewModel($template), 'posts' => new PostIterator(), 'wp' => new WordPressProxy()]);
 }