gpt4 book ai didi

symfony - 如何在 SonataAdminBundle 中覆盖每个实体的模板

转载 作者:行者123 更新时间:2023-12-02 17:07:16 25 4
gpt4 key购买 nike

我想在每个管理员/实体的基础上覆盖 CRUD 列表模板。

假设我有一个名为 MyAdminClass 的管理类。我想通过将模板添加到 app/Resources/SonataAdminBundle/Views/CRUD 来覆盖该类的 CRUD 列表模板,而不是整个应用程序。我怎样才能实现这个目标?

另外,我如何覆盖一组模板而不是一个模板?

最佳答案

表格the documentation :

If you wish, you can specify custom templates on a per Admin mapping basis. Internally, the CRUDController fetches this information from the Admin class instance, so you can specify the templates to use in the Admin service definition:

XML:

<service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
<tag name="sonata.admin" manager_type="orm" group="Content" label="Post"/>
<argument />
<argument>Acme\DemoBundle\Entity\Post</argument>
<argument />
<call method="setTemplate">
<argument>edit</argument>
<argument>AcmeDemoBundle:PostAdmin:edit.html.twig</argument>
</call>
</service>

Yaml:

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]]

使用setTemplates的示例:

XML:

<service id="sonata.admin.post" class="Acme\DemoBundle\Admin\PostAdmin">
<!-- ... -->

<call method="setTemplates">
<argument type="collection">
<argument key="edit">
AcmeDemoBundle:PostAdmin:edit.html.twig
</argument>
<argument key="list">
AcmeDemoBundle:PostAdmin:list.html.twig
</argument>
</argument>
</call>
</service>

Yaml:

services:
sonata.admin.post:
# ...

calls:
- [setTemplates, [{edit: AcmeDemoBundle:PostAdmin:edit.html.twig, list: AcmeDemoBundle:PostAdmin:list.html.twig }]]

关于symfony - 如何在 SonataAdminBundle 中覆盖每个实体的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23321650/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com