<?php
namespace WAM\Bundle\CoreBundle\Util\Traits;
use Twig\Environment;
use WAM\Bundle\CoreBundle\Util\Interfaces\RendererAwareInterface;
/**
* @author Gerard Rico <grico@wearemarketing.com>
*/
trait RendererTrait
{
protected ?Environment $twig = null;
public function render(string $template, array $context = []): string
{
if (is_null($this->twig)) {
throw new \LogicException('Twig is not initialized yet. Did you forget to add '.
RendererAwareInterface::class.' with autoconfigure or a setTwig method call?');
}
return $this->twig->render($template, $context);
}
public function setTwig(Environment $twig): void
{
$this->twig = $twig;
}
}