/** * Render the template and layout. * @param array $data * @return string */ public function render(array $data = array()) { try { $this->data($data); unset($data); extract($this->data); ob_start(); if ($this->exists()) { include $this->path(); } else { throw new LogicException('The template "' . $this->name->getName() . '" could not be found at "' . $this->path() . '".'); } $content = ob_get_clean(); if (isset($this->layoutName)) { $layout = $this->engine->make($this->layoutName); $layout->sections = array_merge($this->sections, array('content' => $content)); $content = $layout->render($this->layoutData); } return $content; } catch (LogicException $e) { if (ob_get_length() > 0) { ob_end_clean(); } throw $e; } }
/** * Get the template path. * @return string */ public function path() { return $this->name->path(); }
public function renderErrorHandler($errno, $errstr, $errfile, $errline) { ob_end_clean(); throw new LogicException('The template "' . $this->name->getName() . '" producing error. ' . $errstr . ', on file: ' . $errfile . ', on line: ' . $errline); }
/** * Create a new Name instance. * @param Engine $engine * @param string $name */ public function __construct(Engine $engine, $name) { parent::__construct($engine, $name); $this->setEngine($engine); $this->setName($name); }
/** * Check if a template exists. * @param string $name * @return boolean */ public function exists($name) { $name = new Name($this, $name); return $name->doesPathExist(); }
/** * Check if a template exists. * @param string $name * @return boolean */ public function exists($name) { $name = new Name($this, $name); return $name->exists(); }