5
votes

I created a new bundle where twig files shall be included. From default there is already a twig file added by the generate bundle command line (in src/TestBundle/Resources/views/test.html.twig). There is also the render-command added automatically in IndexAction:

return $this->render('TestBundle:test.html.twig', $data);

But when I call the IndexAction, I get a template not found error, and the error says, that symfony only looked in

/app/Resources/views, 
/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form

but not in /src/TestBundle/...

Why does symfony ignore the bundle Resources? And how could I change that?

4
very strange. Is the testbundle registered in the appkernel class?Matteo
yes it is, and I already used services etc. in that bundle, but no twig yetAsara

4 Answers

7
votes

I had the same issue with Symfony 3.3, and eventually, through trial and error, discovered that you have to use @ followed by the bundle name, BUT omit the word 'Bundle' from the namespace. So...

@MyFabulousUserBundle/Email/reset_password.html.twig

...did not work, but:

@MyFabulousUser/Email/reset_password.html.twig

did!

2
votes

I was having the same issue, I could use my template with the syntax:

$this->render('@TestBundle/Test/test.html.twig', $data);

but if I tried to use the syntax:

$this->render('TestBundle:Test:test.html.twig', $data);

I had the same error message. After a long and fastidious search, it turned out that what was missing was this line in my config.yml:

framework:
    templating:
        engines: ['twig']
0
votes

You must not remove the sub-folder delimiter.

When a template lives at

TestBundle/Resources/views/

Do this

return $this->render('TestBundle::test.html.twig', $data);

When a template lives in a sub-folder like

TestBundle/Resources/views/Folder/

Use this

return $this->render('TestBundle:Folder:test.html.twig', $data);

You can read the doc here.

0
votes

I had the same problem too with SF 3.3. I think the error message is generic, Symfony, does not list your custom bundles in the error message when it cannot find the template.

In my case, it was simply that I had the name of the folder wrong

$twig->render("UserBundle:Email:registrationComplete.html.twig")

I was just missing an 's' to Email, as my folder was named Emails.

So make sure that the specified template path does exists. Sometimes, it can also be the cache if you just added the template