Override symfony 2 sonataAdminBundle pattern

how can we redefine the sonata package layout for one admin class as I created 3 Admin Class userAdmin, productAdmin, ticketAdmin now I want to redefine the action to edit ticketAdmin and change the template and add extra code there.

+5
symfony sonata-admin
source share
2 answers

If you do not want to create an additional controller, you can use this method mentioned in the docs:

Administrator documentation - Help - Templates (wizard) - 20.6. Template customization

services: sonata.admin.post: class: Acme\DemoBundle\Admin\PostAdmin tags: - { name: sonata.admin, manager_type: orm, group: "Content", label: "Post" } arguments: - ~ - Acme\DemoBundle\Entity\Post - ~ calls: - [ setTemplate, [edit, AcmeDemoBundle:PostAdmin:edit.html.twig]] 

And place your template under Resources / Views / PostAdmin / edit.html.twig. Just copy the source template from the SonataAdmin package and start overriding.

Blogged at: Override list branch template in SonataAdminBundle - webDEVILopers blog

+7
source share

You can use:

Controller:

custom action in SonataAdminBundle

Template:

 // in your admin class public function getTemplate($name) { switch ($name) { case 'edit': return 'AcmeMyBundle::my-custom-edit.html.twig'; break; default: return parent::getTemplate($name); break; } } 
+14
source share

All Articles