<?php
namespace Boab\CmsBundle\View;
use Twig\TemplateWrapper;
class View extends AbstractView implements ViewInterface
{
private $template;
private $locator;
private $twigEngine;
public function __construct(TemplateWrapper $twigEngine, ViewLocator $locator)
{
$this->twigEngine = $twigEngine;
$this->locator = $locator;
}
public function setTemplate($template)
{
$this->template = $template;
}
public function getTemplate()
{
return $this->template;
}
public function render(array $data = [])
{
//dump($this->template);
$data = array_merge($this->fields, $data);
if ('twig' === $this->getExtension($this->template)) {
return $this->twigEngine->render($data);
}
$template = $this->locator->load($this->template);
return $this->__render($template);
}
public function __toString()
{
return $this->render();
}
}