Symfony SonataAdmin 模板 [英] Symfony SonataAdmin Templates

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

问题描述

我正在尝试修改 SonataAdmin 模板.我有一个具有路径属性的 Image 实体.我创建了一个 ImageAdmin 类,并将其集成到 SonataAdmin 中.我想修改 admin-list-view 以将路径包装在 img 标签中,以便实际显示图像.有谁知道我该怎么做?

I am trying to modify the SonataAdmin templates. I have an Image entity that has a path property. I created an ImageAdmin class and this is integrated into sonataAdmin. I would like to modify the admin-list-view to wrap the path in an img tag so that the image is actually displayed. Does anyone know how I can do this?

谢谢!

推荐答案

有两种方法可以使用您自己的模板.

There are 2 ways to use your own templates.

在配置文件中:

sonata_doctrine_orm_admin:
    entity_manager: 

    templates:
        form:
            - SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig
        filter:
            - SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig
        types:
            list:
               ...

            show:
                ...
                image: YourBundle:YourFolder:yourtemplate.html.twig

并在字段定义文件中:

<?php
            namespace ...;

            use Sonata\AdminBundle\Admin\Admin;
            use Sonata\AdminBundle\Form\FormMapper;
            use Sonata\AdminBundle\Datagrid\DatagridMapper;
            use Sonata\AdminBundle\Datagrid\ListMapper;
            use Sonata\AdminBundle\Show\ShowMapper;

            class ImageAdmin extends Admin
            {
                protected function configureShowField(ShowMapper $showMapper)
                {
                    $showMapper
                        ...
                        ->add('image', 'image')
                        ...
                    ;
                }
            }
        ?>

OR 第二种方式:

    <?php
        namespace ...;

        use Sonata\AdminBundle\Admin\Admin;
        use Sonata\AdminBundle\Form\FormMapper;
        use Sonata\AdminBundle\Datagrid\DatagridMapper;
        use Sonata\AdminBundle\Datagrid\ListMapper;
        use Sonata\AdminBundle\Show\ShowMapper;

        class ImageAdmin extends Admin
        {
            protected function configureShowField(ShowMapper $showMapper)
            {
                $showMapper
                    ...
                    ->add('image', 'string', array('template' => 'YourBundle:YourFolder:yourtemplate.html.twig'))
                    ...
                ;
            }
        }
    ?>

然后将下面的代码复制到您的模板中:

And then copy the code below to your template:

{% extends 'SonataAdminBundle:CRUD:base_show_field.html.twig' %}


{% block field %}
    <img src="{{ asset('uploads/media/') }}{{ value|nl2br }}"/>
{% endblock %}

这篇关于Symfony SonataAdmin 模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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