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: 229
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