Symfony2 & Twig - theming file upload widget

Posted by Sacred Socks on Stack Overflow See other posts from Stack Overflow or by Sacred Socks
Published on 2012-11-13T14:32:28Z Indexed on 2014/08/19 16:21 UTC
Read the original article Hit count: 232

Filed under:
|

I have an Symfony2 edit form for an entity and one of the fields is for the user's profile picture.

I'm trying to theme the Twig file upload widget so that the current picture set for the field is displayed above the file input.

So far, I have:

{% form_theme edit_form _self %}
{% block field_widget %}
    {% set type = type|default('text') %}

    {% if type == 'file' %}
        <img src="{{ value }}" /> 
    {% endif %}

    {{ block('form_widget_simple') }}
{% endblock %}

All works well except that the value variable is blank (which makes sense I guess).

My question is how can I get hold of the path to the file? Is there a way to pick it out of the form values for the field? Could I perhaps pass it through as an option to the field?

Srz if this is a dumb question, still pretty new to Symfony and Twig..

© Stack Overflow or respective owner

Related posts about symfony2

Related posts about twig

  • Another Twig Improvements

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
    Hi all! We are here again to intorduce you some of our new NetBeans 7.3 features. Today we'll show you some another Twig improvements. So let's start! Code Templates First feature is about Code Templates. We added some basic templates to improve your Editor experience. You will be really… >>> More

  • Symfony2 Include in html in Twig

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I am developing an application usin Symfony2 and twig for templates. I am using a 3 level structure for templates. Base.html.twig, layout.html.twig and childtemplate.html.twig. The problem is I am trying to include one example.html (common html file) in the next child template by using include but… >>> More

  • Twig Code Completion

    as seen on Oracle Blogs - Search for 'Oracle Blogs'
    Hi all! After few weeks we have a new feature for you which will be available in upcoming NetBeans 7.3. It's about new code completion in Twig files! So let us introduce it a bit. Now we hopefully support all of Twig built-in elements. It means Tags, Filters, Functions, Tests and Operators… >>> More

  • Twig Template For loop Results

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I am trying to print out a the contents of an array but am not getting the expected results. any help is much appreciated: PHP code: $list[1]['first_name'] = 'Joe'; $list[1]['last_name'] = 'Smith'; $list[2]['first_name'] = 'John'; $list[2]['last_name'] = 'brand'; $data = array( 'customer'… >>> More

  • Twig templates, inheritances and block usage

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I've created three templates using Twig. The first one has block A defined in it, the second one extends from the first one, but includes a third template which sets the content of block A. When loading, through the browser, the url which renders b.html.twig, the content in block A (defined by the… >>> More