문제

how can we override sonata bundle layout for a single Admin class like i have created 3 Admin Class userAdmin, productAdmin, ticketAdmin now i want to override ticketAdmin edit action and edit template and add some extra code there.

도움이 되었습니까?

해결책

If you don't want to create an extra controller you can use this method mentioned in the docs:

Admin's documentation - Reference - Templates (master) - 20.6. Configuring templates

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 put your template in Resources/views/PostAdmin/edit.html.twig. Just copy the original template from the SonataAdmin Bundle and start overriding.

Blogged at: Override list view twig template in SonataAdminBundle – webDEVILopers Blog

다른 팁

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;
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top