Symfony2 cannot find template file

I'm having problems using twig templates for email in SF2.

First I created a template file located at MainBundle/Resources/views/Email/InviteNewUsers.twig

Then I displayed the view as the body of my email: $this->get('mailer')->send($this->renderView('MainBundle:Email:InviteNewUsers.twig', array('code' => $invite->getCode())));

Unfortunately, this causes an error: Unable to find template "MainBundle:Email:InviteNewUsers.twig"

Is there something wrong with my file location or my render command?

It was assumed that I might need a type in the template name, so I tested it with InviteNewUsers.txt.twig and got the same error.

+4
source share
1 answer

I believe the name of the branch template should be InviteNewUsers.{_format}.twig . therefore it should be something like InviteNewUsers.html.twig , InviteNewUsers.xml.twig or InviteNewUsers.text.twig , etc.

EDIT:

Also, if your namespace contains the first directory, similar to {Company}\BaseBundle\... , then your template path should be {Company}MainBundle:Email:InviteNewUsers.text.twig

+10
source

All Articles