如何在Sonata Admin中覆盖单个模板和操作


How to override single template and action in Sonata Admin?

如何在Sonata Admin中覆盖单个模板和操作?

在Symfony 1中,这很简单——从缓存中获取并复制到后端的文件夹,但我如何在Sonata Admin中实现它?

您必须定义新模板和要覆盖的特定操作。

文档提供了一个有用的例子:

http://sonata-project.org/bundles/admin/2-2/doc/reference/action_show.html#setting-上一个定制的显示模板-可靠的

sonata_admin:
    title: Acme
    title_logo: public/img/logo.png
    options:
        title_mode: 'single_image'
    templates:
        # default global templates
        layout:  :sonata:standard_layout.html.twig
        ajax:    SonataAdminBundle::ajax_layout.html.twig
        dashboard: SonataAdminBundle:Core:dashboard.html.twig
        # default actions templates, should extend a global templates
        list:        SonataAdminBundle:CRUD:list.html.twig
        show:        SonataAdminBundle:CRUD:show.html.twig
        edit:        SonataAdminBundle:CRUD:edit.html.twig
        user_block:  acmeUserBundle:Core:user_block.html.twig

更全球化的文档:

http://sonata-project.org/bundles/admin/2-2/doc/reference/templates.html

如果你想覆盖一个单一的管理模板(在下面的例子中编辑)

app.admin.foo:
    class: AppBundle'Admin'FooAdmin
    arguments: [~, AppBundle'Entity'Foo, AppBundle:FooAdmin]
    tags:
        - { name: sonata.admin, manager_type: orm, group: admin, label: Foo }
    calls:
        - [ setTemplate, ['edit', 'AppBundle:Admin/Foo/CRUD:edit.html.twig']]