Skip to content
Advertisement

Symfony 3.4 Use view inside my bundle

I’ve some trouble for the configuration of a new repository using Symfony 3.4. I’ve used the symfony command for create him with last LTS (3.4) and I add a new Bundle using command too. My new Bundle is up and work well but I can’t use view stored inside this bundle.

I show you the structure of my Bundle :

structure

I want to use this index.html.twig in my controller like this :

JavaScript

But when I try to render it I’ve this error.

Unable to find template “ListerListerBundle:Default:index.html.twig” (looked into: /home/emendiel/Data/Code/Perso/WebLister/app/Resources/views, /home/emendiel/Data/Code/Perso/WebLister/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).

I understand what that say, my folder is not where symfony search my view but I don’t found how I can said to Symfony go in “ListerBundle/Ressources/views”

In my oldest project that was work without other configuration.

Info: I use my bundle as reusable bundle.

Regards,

PS: This is my autoload part in composer.json

JavaScript

PSS: My AppKernel :

JavaScript

And Again: Here My dependencyInjection

enter image description here

And the content of files :

Configuration.php

JavaScript

ListerListerExtension.php

JavaScript

Solution: from @Cerad

@ListerLister/Default/index.html.twig

Original response from @Cerad

For some reason, S3.4 no longer likes the Bundle:Dir:name approach to specifying twig paths and the generate:bundle command has not yet been updated. Not sure if it is a bug or feature. The @ListerLister/Default/index.html.twig path suggested above should work. Try bin/console debug:twig to see your twig namespaces paths. – Cerad

Advertisement

Answer

The basic problem appears to be that in S3.4, twig template paths such as ‘ListerListerBundle:Default:index.html.twig’ are no longer supported.

Replace the path in the controller with:

JavaScript

And all should be well. If you are ever not sure what the actual namespace prefix is then run:

JavaScript

to list them.

S3.3 still works fine so this is something that changed in 3.4. Supposed to be using the namespaced format anyways so this is not a big deal.

I did file an issue about this on github: https://github.com/sensiolabs/SensioGeneratorBundle/issues/587

We shall see what the maintainers have to say.

Update: The great and powerful Fabpot himself replied to my issue. If you want to keep using the ‘ListerListerBundle:Default:index.html.twig’ format for templates then edit your app/config/config.yml file:

JavaScript

You should only do this if you have legacy code which still uses the old format. Use twig namespaces for all new code.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement