Cannot inject Templating on Symfony 4 Service Cannot inject Templating on Symfony 4 Service symfony symfony

Cannot inject Templating on Symfony 4 Service


You have to install symfony/templating

composer require symfony/templating

change a little bit config/packages/framework.yaml

framework:    templating:        engines:            - twig


I managed to do it with Twig Environment and HTTP Response

<?phpnamespace App\Controller;use Twig\Environment;use Symfony\Component\HttpFoundation\Response;class MyClass{    private $twig;    public function __construct(Environment $twig)    {        $this->twig = $twig;    }    public function renderTemplateAction($msg)    {        return new Response($this->twig->render('myTemplate.html.twig'));    }}


Most likely you don't have Templating included in your project, in Symfony 4 you have to require it explicitly:

composer require symfony/templating