Symfony2 & Twig - theming file upload widget Symfony2 & Twig - theming file upload widget symfony symfony

Symfony2 & Twig - theming file upload widget


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


So it looks I'm terrible at googling for Symfony stuff. I eventually found this part of the Symfony cookbook: http://symfony.com/doc/master/cookbook/form/form_customization.html

Symfony2 calls it a Form Type Extension and they actually use adding a image tag to the file widget as their example.