BiGGiE0344
BiGGiE0344

Reputation: 141

unable to find template, after generating bundle

ok this might be a very strange thing. it's not the first time I work a symfony project but:

I used the symfony generate:bundle command and after that I created a bundle. Lets call it "CrimeBundle".

I saw it made a folder inside the src/

It also made automatically a DefaultController and an index.html.twig file.

Now whenever I use:

return $this->render('CrimeBundle:Default:index.html.twig');

it doesn't work: I get the error:

Unable to find template "CrimeBundle:Default:index.html.twig" (looked into: /Users/admin/sites/solve/app/Resources/views, /Users/admin/sites/solve/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).

however it works whenever I use the namespaced twig path like:

return $this->render('@Crime/Default/index.html.twig');

I like the first option, because on my other projects I use it too. None of them are the same version, currently I use: 3.4.1 Again the file is there, because it works with namespaced twig paths.

I can't understand why return $this->render('CrimeBundle:Default:index.html.twig'); wouldn't work as symfony generated this code.

Upvotes: 6

Views: 1978

Answers (2)

Giancarlos Salas
Giancarlos Salas

Reputation: 21

Maybe you can create a pull request for this file SensioGeneratorBundle/bundle/DefaultController.php.twig

Upvotes: 0

Sergei Kutanov
Sergei Kutanov

Reputation: 825

According to this - https://symfony.com/doc/3.4/templating.html#referencing-templates-in-a-bundle That's the only reference type the support for bundle templates

@BundleName/directory/filename.html.twig

If you go to docs for symfony 3.1 you'll see that was the last version that supported old reference

AcmeBlogBundle:Blog:index.html.twig

Upvotes: 5

Related Questions