unable to find template, after generating bundle
Asked Answered
T

2

6

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.

Tatiania answered 5/12, 2017 at 19:58 Comment(1)
Looks like it is a bug.. It works with version 3.3.14 and it does not work with version 3.4.1. With both versions have another issue which you can read on #45243338Osugi
A
5

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
Allseed answered 6/12, 2017 at 1:1 Comment(1)
I totally understand but, what I don't understand is why is it automatically being created by symfony. I mean if it doesn't work like that, why is the generate:bundle command using the wrong reference.Tatiania
F
0

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

Finale answered 17/12, 2017 at 5:48 Comment(1)
The link might answer the question but please provide a description her. Else once the link changes your answer turns useless.Presidentship

© 2022 - 2024 — McMap. All rights reserved.