symfony2: customizing bundles overriding directory - symfony

For overriding Bundles template , at the first level Symfony search inside app/Resources/AcmeSampleBundle directory if it doesn't exist then it read template from src/Acme/SampleBundle.
Is there any way for customizing first level directory? for example : app/Resources/AllBundles/

You could use your custom template locator by change service 'templating.locator'. Let check how LiipThemeBundle do this.

Related

how to customize the style of the form made from twig on Symfony?

hello I was wondering how to customize the form on symfony instead of having already a ready-made template (especially the bootstrap one).
Hello here is the solution to this problem :
To start, here is the place where you can change the theme of the forms to Symfony:
// project_name/config/packages/twig.yaml
twig :
...
form_themes: ['bootstrap_4_layout.html.twig']
if you want to see the default packages that are available you have to go to the following folder :
project_name/vendor/twig-bridge/Resources/views/Form
Now you can notice that twig file names match the style that you can add for your forms made with twig
so now if you really want to make your own style of form just create a twig file in that same folder 'project_name/vendor/twig-bridge/Resources/views/Form' and then replace that filename with 'bootstrap_4_layout.html.twig' in 'project_name/config/packages/twig.yaml'

EasyAdmin Using your Own Templates Problem

I am trying to override "new" template for EasyAdmin but system ignores template code.
Here is the relevant part of easy_admin.yaml
entities:
# List the entity class name you want to manage
Places:
class: App\Entity\Places
templates:
list: 'asdfasdf'
As you see, value of list attribute is invalid but system ignores it and works without error and i can not override the template.
Do you have a suggestion?
So, as I mentioned in the comment - for some reason easyadmin doesn't give any errors if specified template doesn't exists. So, you just need to place your new template in templates folder, in example, templates/admin/listPlaces.html.twig and then specify correct path in easyadmin's config file, in example:
entities:
Places:
class: App\Entity\Places
templates:
list: 'admin/listPlaces.html.twig'
If you use EasyAdmin 3.x, for that you can overwrite a specific template specifying it in your entity's Controller or you can create your own folder structures like symfony does.
In this example I am overwriting only the edit template for my 'studient' entity, if you want to change all the edits of your project you must do so by creating the folder structure as symfony does.
public function configureCrud(): Crud
{
return Crud::new()
->overrideTemplate('crud/edit', 'studient/edit.html.twig')
;
}
You can even combine both methods. Suppose that in addition to modifying only the template 'edit' of studient you want to modify the way in which easyadmin displays the flash messages for that you only have to create this structure in your templates folder: "templates\bundles\EasyAdminBundles\flash_messages.html.twig"
I leave the link with the documentation for EasyAdmin 3.x
overriding-templates

sonata adminbundle : customize show action [duplicate]

I want to override the default SonataAdmin Template.
I create a standard_layout.html.twig in my Namespace/bundle/resources/views
(same structur, same file name, same content)
I copied all the content of the source template in my target template, i just edit some part of the target off course....and nothing
thanks for your help
Bye
You have the solution of bundle heritance http://symfony.com/doc/current/cookbook/bundles/inheritance.html which allows, not only override templates but methods too.
Or you have http://symfony.com/doc/2.0/book/templating.html#overriding-bundle-templates which focusing only on templates.
With this last, you can try to create :
app/Resources/SonataAdminBundle/views/CRUD/base_show_field.html.twig

Default custom route on SonataORMAdmin list view

Refering to the SoanataORMAdmin's documentation, it is possible to change the default route of object links.
By default, it's the edit route. I don't want it at all and need to change it to show without override all my admin class.
What is the better way to override the default route ?
Thanks.
The best way is to override the twig by extending SonataORMAdminBundle.
To do this, you need to :
install SonataEasyGenerate Bundle
use the command php app/console sonata:easy-extends:generate SonataORMAdminBundle
this will generate a new repository Application/Sonata/DoctrineORMAdminBundle
Then you need to go to Application/Sonata/DoctrineORMAdminBundle/Ressources/views/CRUD and paste the twigs from the vendors (vendor/Sonata/DoctrineORMAdminBundle/Ressources/views/CRUD)
Finally, change the links in the twigs.
For example, if you want to call the list view to call the show route for a many to one relation :
edit list_orm_many_to_one.html.twig to call generateObjectUrl('show',...) instead of generateObjectUrl('edit',...)
Hope this will help.

Symfony2 - override template bundle

I want to override the default SonataAdmin Template.
I create a standard_layout.html.twig in my Namespace/bundle/resources/views
(same structur, same file name, same content)
I copied all the content of the source template in my target template, i just edit some part of the target off course....and nothing
thanks for your help
Bye
You have the solution of bundle heritance http://symfony.com/doc/current/cookbook/bundles/inheritance.html which allows, not only override templates but methods too.
Or you have http://symfony.com/doc/2.0/book/templating.html#overriding-bundle-templates which focusing only on templates.
With this last, you can try to create :
app/Resources/SonataAdminBundle/views/CRUD/base_show_field.html.twig

Resources