如何覆盖 Sonata Media Bundle 模板? [英] How to override Sonata Media Bundle templates?

查看:22
本文介绍了如何覆盖 Sonata Media Bundle 模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 SonataAdminBundle 来创建后台,并且我在 2 天前集成了 SonataMediaBundle(应用开发版).然而,来自奏鸣曲包的编辑/创建模板有一些错误!我已经修复了它们(它们只是树枝错误).

I'm currently using SonataAdminBundle for the creation of a Back Office and I've integrated SonataMediaBundle (app-dev version) 2 days ago. The edit/create template from sonata bundle however has some errors! I've fixed them (and they are just twig errors).

但我不能只对供应商进行更改.覆盖 SonataMediaBundle 模板的正确方法是什么?
我已经尝试过经典的 AdminBundle 方式,但它不起作用!代码如下:

But I can't just make the changes in the vendor. What is the correct way to overwrite the SonataMediaBundle templates?
I've tried the classic AdminBundle way but it doesn't work! here's the code:

sonata.admin.media:
        class: Acme\AdminBundle\Admin\MediaAdmin
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Media Library", label: "Media" }
        arguments:
            - ~
            - ~
            - ~
            - @sonata.media.pool
        calls:
            - [ setTemplate, [edit, AcmeAdminBundle:Media:edit.html.twig]] 

推荐答案

其实,现在我已经想通了.为了覆盖媒体预览或表单,您应该覆盖表单小部件,或自定义您的表单主题.

Actually, now I've figured it out. In order to overwrite the media Preview or form, you should overwrite the form widget, or customize your form theme.

示例:在 config.yml 文件中添加配置:

Example: In the config.yml file add the configuration:

twig:
    form:
        resources:
            # other files
            - 'AdminBundle:Form:mediaPreview.html.twig'

媒体预览文件应如下所示:

The media preview file should look something like this:

{% block sonata_media_type_widget %}
      << your code here >>
{% endblock sonata_media_type_widget %}

这篇关于如何覆盖 Sonata Media Bundle 模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆