Could not find template after creating package

OK, this can be very strange. This is not the first time I am working on a symfony project, but:

I used the symfony generate: bundle command, and after that I created the package. Let's call it "CrimeBundle".

I saw that he created a folder inside src /

He also automatically created DefaultController and the index.html.twig file.

Now when I use:

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

it does not work: I get an error message:

Cannot find the pattern "CrimeBundle: Default: index.html.twig" (viewed: / 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 a path with names with names:

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

I like the first option, because in my other projects I also use it. None of them are the same version, I am currently using: 3.4.1 Again, there is a file because it works with branch paths with names.

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

+5
source share
2 answers

Accordingly - https://symfony.com/doc/3.4/templating.html#referencing-templates-in-a-bundle The only reference type of support for bundle templates

 @BundleName/directory/filename.html.twig 

If you go to the docs for symfony 3.1, you will see that this was the latest version supporting the old link

 AcmeBlogBundle:Blog:index.html.twig 
+4
source

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

0
source

Source: https://habr.com/ru/post/1273868/


All Articles