Example #1
0
 /**
  * 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');
 }
Example #2
0
 /**
  * Renders the specified template file.
  *
  * @param string $file
  * @param array  $variables
  * @param array  $attributes
  *
  * @return string
  * @throws renderer\buckets\exceptions\StrictVariableException
  * @throws renderer\buckets\exceptions\VariableWriteException
  */
 public function render(string $file, array $variables = [], array $attributes = []) : string
 {
     foreach ($variables as $key => $value) {
         $this->variables->add($key, $value);
     }
     foreach ($attributes as $key => $value) {
         $this->attributes->add($key, $value);
     }
     return $this->engine->render($file, $this->sections, $this->variables, $this->attributes);
 }