How to display the current picture above the upload field in SonataAdminBundle?

后端 未结 7 2055
广开言路
广开言路 2021-02-01 20:31

I am using SonataAdminBundle (with Doctrine2 ORM) and I have successfully added a file upload feature to my Picture model.

I would like, on the

7条回答
  •  情深已故
    2021-02-01 20:38

    You can easily do this on show page by template attribute pass on $showmapper

    ->add('picture', NULL, array(
        'template' => 'MyProjectBundle:Project:mytemplate.html.twig'
    );
    

    and inside your template you get current object so u can call get method and pull image path

    {% block name %}{{ admin.trans(field_description.label) }}{% endblock %}
    
        
        
    {% block field %}{{ value|nl2br }}{% endblock %}

    To show image in edit mode you have to override fileType or you have to create your own customType on top of fileType

    There is also some bundle which is having this kind of functionality check out this GenemuFormBundle

提交回复
热议问题