I want get form field type and set class fot field type
i try:
{# Form field row #}
{% block form_row %}
{% spaceless %}
The answer from MatsRietdijk is right, but as of Symfony 2.3 the index of the type seems to have changed from 2 to 1. As a result, {{ form.vars.block_prefixes.1 }}
will return checkbox
, date
, choice
, etc.
You can use it to add a class to the form row when making application-wide customizations:
{% block form_row %}
{{ form_label(form) }}
{{ form_widget(form) }}
{{ form_errors(form) }}
{% endblock form_row %}
Then you can apply CSS rules:
div.form_row.text {color:Red;}
If you use Twitter bootstrap, you may have problems since the .checkbox
class exists in bootstrap. I suggest to use a prefix for Symfony forms rows:
{% block form_row %}
{{ form_label(form) }}
{{ form_widget(form) }}
{{ form_errors(form) }}
{% endblock form_row %}
The rules in the CSS files will be different:
div.form_row.symfony_text {color:Red;}
Twitter bootstrap form theme is now included in Symfony 2.6.