I am using Symfony v3.3.13 and Sonata Admin Bundle 3.27.0 with TWIG v2.4.4
I have a little problem understanding how twig template paths work. I have recently needed to load a new template for a list view field in
SonataAdminBundle
->add('coords', null, ['template' => 'SonataAdmin/CRUD/geography_point_list.html.twig']);
app/Resources/views/SonatAdmin/Crud
AppBundle::SonataAdmin/CRUD/geography_point_list.html.twig
src/AppBundle/Resources/views/SonatAdmin/Crud
:
/
AppBundle:SonataAdmin:CRUD:geography_point_list.html.twig
Unable to find template
app/Resources/views/SonataAdmin/CRUD
src/AppBundle/Resources/views/SonataAdmin/Crud
->add('coords', null, ['template' => 'App:SonataAdmin:CRUD:geography_point_list.html.twig']);
->add('coords', null, ['template' => 'AppBundle:SonataAdmin:CRUD:geography_point_list.html.twig']);
->add('coords', null, ['template' => 'AppBundle:app:Resources:views:SonataAdmin:CRUD:geography_point_list.html.twig']);
->add('coords', null, ['template' => 'App::SonataAdmin:CRUD:geography_point_list.html.twig']);
->add('coords', null, ['template' => 'AppBundle::SonataAdmin:CRUD:geography_point_list.html.twig']);
SonataAdminBundle:CRUD:list.html.twig
SonataAdminBundle
app/Resources/views
AppBundle
AppBundle
app
config
Resources
AppBundle
I think it doesn't work because you should try BundleName:DirectoryInViewsFolder:Subfolder/template.html.twig
. So in your case it is AppBundle:SonataAdmin:CRUD/geography_point_list.html.twig
.
Right, you can put them there.
a) In symfony 3 i don't think so.
b) I guess what in app/Resources
and app/config
there are global resources and configs for your application. And resources and configs for your bundle you put in src/BundleName/Resources
and src/BundleName/config
folders.
BTW you can also use your custom templates paths:
config.yml
twig:
paths:
'%kernel.project_dir%/src/YourBundle/templates': templates
YourAdmin.php
->add('coords', null, ['template' => '@templates/geography_point_list.html.twig']);
UPDATE
This answer is not fully correct. It was helpful for Evren Yurtesen but you should see the right answer here.