Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony does not search in bundle for twig files

Tags:

php

twig

symfony

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?

like image 318
Asara Avatar asked Dec 04 '16 19:12

Asara


2 Answers

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!

like image 200
Russ Avatar answered Oct 04 '22 17:10

Russ


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']
like image 21
Julien Rouvier Avatar answered Oct 04 '22 17:10

Julien Rouvier