Reputation: 31548
I know that i can do this in twig
{{ form_widget(form.age, { 'attr': {'size': '5'} }) }}
But what if i want to do it in my form and for all textboxes
Upvotes: 1
Views: 241
Reputation: 11351
Take a look at this document, it explains everything about customizing form rendering in symfony:
http://symfony.com/doc/current/cookbook/form/form_customization.html
For example, to customize the rendering of the "integer" fields (the textboxes used for "integer" properties), do this:
{% form_theme form _self %}
{% block integer_widget %}
{% spaceless %}
{% set type = type|default('number') %}
{% set attr = attr|merge({'size': '5' }) %}
{{ block('form_widget_simple') }}
{% endspaceless %}
{% endblock %}
You can see how each field is rendered by default in https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
This will work for all forms in that particular template. If you want to use this customization in several templates you will need to put this in a separate template, it is all explained in the doc
Upvotes: 2