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..
Symfony is a feature-rich back-end framework that is used to build complex applications. Many developers still prefer the lightweight Silex micro-framework or the Symfony MicroKernel, and Symfony is a widely used application framework among open-source developers.
Symfony is an open-source PHP web application framework, designed for developers who need a simple and elegant toolkit to create full-featured web applications. Symfony is sponsored by SensioLabs. It was developed by Fabien Potencier in 2005.
Both PHP Laravel and Symfony PHP are developed on MVC architecture, but in terms of component reusability and code modularity, Symfony has the edge over Laravel on this one. It structures the program in an organised fashion and becomes the perfect fit for larger and complex projects.
Fabien Potencier Being a developer by passion, he immediately started to build websites with Perl. But with the release of PHP 5, he decided to switch focus to PHP, and created the symfony framework project in 2004 to help his company leverage the power of PHP for its customers.
A better way to customize the file widget will be
{% block file_widget %}
{% spaceless %}
//Your custom content here
{% endspaceless %}
{% endblock file_widget %}
For example:
{% block file_widget %}
{% spaceless %}
<td>{% set type = type|default('file') %}
<input type="{{ type }}" {{ block('widget_attributes') }} />
</td>
{% endspaceless %}
{% endblock file_widget %}
Remember that "{% spaceless %}" is very important
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With