Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 can't find template file

Tags:

twig

symfony

I am having issues using twig templates for email in SF2.

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

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

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

is there something wrong with my file placement or my render command?

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

like image 967
MrGlass Avatar asked Dec 26 '22 21:12

MrGlass


1 Answers

I believe the name of twig template needs to be InviteNewUsers.{_format}.twig. so it must be something like InviteNewUsers.html.twig, InviteNewUsers.xml.twig, or InviteNewUsers.text.twig etc

EDIT:

Also if your namespace includes first directory something like {Company}\BaseBundle\..., then your template path needs to be {Company}MainBundle:Email:InviteNewUsers.text.twig

like image 182
mask8 Avatar answered Jan 05 '23 11:01

mask8