How to override form_row block in Twig, adding attributes by field type?
Although you say that this is not about customizing the form, this can be achieved with this ... A brief introduction for others reading this now.
The default symfony extension form extensions can be found here .
The default twin theme theme can be found in Symfony / Bridge / Twig / Resources / views / Form / form_div_layout.html.twig .
General information on how to redefine forms can be found in the How to Make Customize Form Visualization chapter in the book, but I will briefly sign it.
form_row Default
{% block form_row %} {% spaceless %} <div> {{ form_label(form) }} {{ form_errors(form) }} {{ form_widget(form) }} </div> {% endspaceless %} {% endblock form_row %}
Form Level Override
Add this to the form template you want to customize:
{% form_theme form _self %}
If you want to put {% block form_row%} in another package / template, use this:
{% form_theme form 'AcmeDemoBundle:Form:fields.html.twig' %}
Now insert your own form_row block after the form_theme declaration or place it in the specified template (in our case it will be AcmeDemoBundle: Form: fields.html.twig).
In my example, we will add the error class if there is an error in the form line and the other class name is the type name of the current field type.
{% block form_row %} {% spaceless %} {
if you want to apply your form_row block throughout the system, add your AcmeDemoBundle: Form: fields.html.twig to your twig.templating.form.resources!
# app/config/config.yml framework: templating: form: resources: - 'AcmeDemoBundle:Form'