I recently installed Symfony & Sonata admin bundle, works fine. Is it possible to change/custom the admin interface (template)? Where can I download these templates? Any tutorial how to do that?
3 Answers
It is possible to change any template. To do that, you need to:
- Install EasyExtendBundle
Run the command $php app/console sonata:easy-extends:generate SonataAdminBundle -d src
Register the generated bundle in AppKernel.php (the name will be ApplicationSonataAdminBundle)
Copy the template you need to extend from the vendor directory and place it under the same hierarchy in your new bundle.
Change your new template and add any block you want
PS: you can do the same thing with the CSS or JS files
You can write your new templates, based or not on the sonata templates and after instruct the sonata admin to display your templates when a page is requested. In the Admin class you have to override the 'getTemplate' method, like this:
public function getTemplate($name)
{
switch ($name) {
case 'edit':
return 'YourBundle:YourFolder:yourEdit.html.twig';
break;
case 'list':
return 'YourBundle:YourFolder:yourList.html.twig';
break;
default:
return parent::getTemplate($name);
break;
}
}
The example overrides the templates for 'edit' and 'list' actions. For the other actions it will get the sonata semplates.
You can simply override any template from the bundle. Check the doc here
By default all the templates are configured in config.yml:
sonata_admin:
templates:
layout: SonataAdminBundle::standard_layout.html.twig
ajax: SonataAdminBundle::ajax_layout.html.twig
list: SonataAdminBundle:CRUD:list.html.twig
show: SonataAdminBundle:CRUD:show.html.twig
edit: SonataAdminBundle:CRUD:edit.html.twig
history: SonataAdminBundle:CRUD:history.html.twig
preview: SonataAdminBundle:CRUD:preview.html.twig
delete: SonataAdminBundle:CRUD:delete.html.twig
batch: SonataAdminBundle:CRUD:list__batch.html.twig
acl: SonataAdminBundle:CRUD:acl.html.twig
action: SonataAdminBundle:CRUD:action.html.twig
select: SonataAdminBundle:CRUD:list__select.html.twig
dashboard: SonataAdminBundle:Core:dashboard.html.twig
search: SonataAdminBundle:Core:search.html.twig
batch_confirmation: SonataAdminBundle:CRUD:batch_confirmation.html.twig
inner_list_row: SonataAdminBundle:CRUD:list_inner_row.html.twig
base_list_field: SonataAdminBundle:CRUD:base_list_field.html.twig
list_block: SonataAdminBundle:Block:block_admin_list.html.twig
user_block: SonataAdminBundle:Core:user_block.html.twig
pager_links: SonataAdminBundle:Pager:links.html.twig
pager_results: SonataAdminBundle:Pager:results.html.twig
history_revision_timestamp: SonataAdminBundle:CRUD:history_revision_timestamp.html.twig
short_object_description: SonataAdminBundle:Helper:short-object-description.html.twig
search_result_block: SonataAdminBundle:Block:block_search_result.html.twig