/** * Render a template with the given parameters. * * If a layout was specified during construction, it will be used; * alternately, you can specify a layout to use via the "layout" * parameter/variable, using a string layout template name * * Layouts specified with $params take precedence over layouts passed to * the constructor. * * @param string $name * @param array $params * @return string */ public function render($name, $params = []) { list($namespace, $viewName) = explode('::', $name); $params = $this->mergeParams($name, $this->normalizeParams($params)); $this->prepareLayout($params); $this->renderer->setView($viewName); $this->renderer->setData($params); return $this->renderer->__invoke(); }
protected function setTemplate(View $view, RootConfig $config) { $template = $config->getTemplate(); if (!$template) { $template = dirname(dirname(dirname(__DIR__))) . '/templates/main.php'; } if (!file_exists($template) && !is_readable($template)) { throw new Exception("Cannot find template '{$template}'."); } $registry = $view->getViewRegistry(); $registry->set('__BOOKDOWN__', $template); $view->setView('__BOOKDOWN__'); }