I\'m new of symfony world. I want to use render inside my service, but I got this error
Call to undefined method renderView
I know t
This works on Symfony +4.2, assuming your application's namespace is App and your mailer class service is named EmailService.
On your Service class:
// ...
private $mailer;
private $templating;
public function __construct( \Swift_Mailer $mailer, \Twig\Environment $templating )
{
$this->mailer = $mailer;
$this->templating = $templating;
}
public function sendEmailRegistration()
{
$message = $this->templating->render('emails/registration.html.twig');
// ...
}
// ...
On your services.yaml
services:
email_service:
class: App\Service\EmailService
arguments: ['@swiftmailer.mailer.default', '@twig']