How to override Sonata Media Bundle templates?

喜你入骨 提交于 2019-12-11 10:08:00

问题


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).

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

回答1:


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.

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



回答2:


You overwrite them in the same way you would any other bundle except Sonata use's easy extends so in App/Resources create a folder called ApplicationSonataMediaBundle or ApplicationSonataAdminBundle and inside this folder create a folder of the same name as the one you are trying to override.

For example I currently use the following:

App/Resources/ApplicationSonataNewsBundle/translations/SonataNewsBundle.en.xliff

To override any of the English translations in their news bundle OR

App/Resources/ApplicationSonataUserBundle/views/layout.html.twig

To override their Layout template.

I would suggest you need to create something along these lines.

App/Resources/ApplicationSonataMediaBundle/views/MediaAdmin/edit.html.twig

and copy the Sonata code into it, then modify as you require.

Hope this helps



来源:https://stackoverflow.com/questions/23080549/how-to-override-sonata-media-bundle-templates

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