symfony 2 sonataAdminBundle override template

核能气质少年 提交于 2020-01-22 22:05:14

问题


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.


回答1:


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




回答2:


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;
    }
}


来源:https://stackoverflow.com/questions/10297821/symfony-2-sonataadminbundle-override-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!