/** * {@inheritdoc} */ public function get(array $fileInfo, array $data = []) : string { $engine = $this->getLoader(); if ($this->request !== null) { // Set uri extensions $engine->loadExtension(new URI($this->request->getUri()->getPath())); } // Set asset extensions $engine->loadExtension(new Asset($this->config['engine']['plates']['asset'] ?? null)); // Get all extensions if (!empty($this->availableExtensions)) { foreach ($this->availableExtensions as $extension) { $engine->loadExtension(is_object($extension) ? $extension : new $extension()); } } if (!$engine->exists($fileInfo['name'])) { throw new Exception('Template "' . $fileInfo['name'] . '" dont exist!'); } // Creat a new template $template = new Template($engine, $fileInfo['name']); // We'll evaluate the contents of the view inside a try/catch block so we can // flush out any stray output that might get out before an error occurs or // an exception is thrown. This prevents any partial views from leaking. ob_start(); try { return $template->render($data); } catch (Throwable $exception) { $this->handleViewException($exception); } }
/** * Create new Template instance. * @param Engine $engine * @param string $name */ public function __construct(Engine $engine, $name) { parent::__construct($engine, $name); $this->engine = $engine; $this->name = new Name($engine, $name); $this->data($this->engine->getData($name)); }
/** * @param Template $template * @param PayloadInterface $payload * @return string */ protected function render(Template $template, PayloadInterface $payload) { return $template->render($payload->getOutput()); }