/** * Process the given queue of template files and * returns the generated output. * * @param string $file * * @return string * @throws RendererException */ public function render(string $file) : string { if ($this->rendering) { throw new RendererException("Cannot call render() inside templates."); } $this->rendering = true; $this->queue->enqueue($file); $this->sections()->declare('content'); ob_start(); while (!$this->queue->isEmpty()) { $file = $this->engine->path($this->queue->dequeue()); if (!file_exists($file)) { throw new \RuntimeException("Cannot find file: {$file}"); } require $file; $this->sections()->populate('content', ob_get_contents(), 'replace'); ob_clean(); if ($this->extended) { $this->extended = false; } } ob_end_clean(); $this->rendering = false; return $this->sections()->fetch('content'); }
/** * Checks if a template file exists. * * @param string $file * * @return bool */ public function exists(string $file) : bool { return file_exists($this->engine->path($file)); }