/** * @returns string Rendered HTML. * @throws \Exception If the template file doesn't exist. */ public function render() { $this->onRender(); if (!is_file($this->settings->templatePath . $this->template)) { throw new \Exception("Template file '{$this->template}' don't exists"); } $template = file_get_contents($this->settings->templatePath . $this->template); $partial = new PartialView($this); return $partial->renderPartial($template); }
private function renderBlockDirective($template) { $matched = preg_match(self::BLOCK_DIRECTIVE_REGEX . 's', $template, $match); if ($matched) { $name = $match[2]; $arguments = $this->extractArguments($match[3]); $body = $match[4]; $partial = new PartialView($this); $rendered = $partial->renderPartial($this->settings->blockDirectives[$name]->render($partial, $arguments, $body)); $template = preg_replace('/' . preg_quote($match[0], '/') . '/', $rendered, $template, 1); return $template; } return null; }