Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:51:17+00:00 2026-06-07T04:51:17+00:00

I am using SonataAdminBundle (with Doctrine2 ORM) and I have successfully added a file

  • 0

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 Show and Edit pages, to display a simple <img src="{{ picture.url }} alt="{{ picture.title }} /> tag just above the relevant form field (provided that the Picture being edited is not new, of course), so that the user may see the current photo, and decide whether to change it or not.

After hours of research, I’ve been unable to figure out how to do it. I suppose I need to override some template, but I’m a bit lost…
Can somebody give me a hint?

Thank you!

Here is the relevant section of my PictureAdmin class.

protected function configureFormFields(FormMapper $formMapper)
{
    $formMapper
        ->add('category', NULL, ['label' => 'Catégorie'])
        ->add('title', NULL, ['label' => 'Titre'])
        ->add('file', 'file', ['required' => false, 'label' => 'Fichier']) // Add picture near this field
        ->add('creation_date', NULL, ['label' => 'Date d\'ajout'])
        ->add('visible', NULL, ['required' => false, 'label' => 'Visible'])
        ->add('position', NULL, ['label' => 'Position']);
}

protected function configureShowFields(ShowMapper $showMapper)
{
    $showMapper
        ->add('id', NULL, ['label' => 'ID'])
        ->add('category', NULL, ['label' => 'Catégorie'])
        ->add('title', NULL, ['label' => 'Titre'])
        ->add('slug', NULL, ['label' => 'Titre (URL)'])
        ->add('creation_date', NULL, ['label' => 'Date d\'ajout'])
        ->add('visible', NULL, ['label' => 'Visible'])
        ->add('position', NULL, ['label' => 'Position']);
        // Add picture somewhere
}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:51:19+00:00Added an answer on June 7, 2026 at 4:51 am

    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

    <th>{% block name %}{{ admin.trans(field_description.label) }}{% endblock %}</th>
    <td>
        <img src="{{ object.getFile }}" title="{{ object.getTitle }}" />
        </br>
        {% block field %}{{ value|nl2br }}{% endblock %}
    </td>
    

    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

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Symfony2 with sonataAdminBundle, sonataUserBundle and FOSUserBundle. I would like to create a
Using EXTJS4, I have created a custom grid. I would like one column to
Using Rails 3.2.0 with haml and sass: I Would like to link an external
I would like to ask about some advices, how to use Symfony2 SonataAdminBundle. I
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Jenkins or Hudson I would like to create a pipeline of builds with
Using Java,I have to fetch multiple sets of values from an XML file to
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using PlayFramework 2.0.1, I have a model : class MyModel extends Model { @Constraints.Required
I have a project with symfony 2 and im using a SonataAdminBundle for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.