symfony - Twig Form Theming - form_label class attribute -
i've been trying override form_row twig extension can render twitter bootstrap style row. twitter boostrap form row should this:
<div class="control-group"> <label class="control-label" for="idofmaininput">label name:</label> <div class="controls"> <input type="text" id="idofmaininput" name="somedumbname"> </div> </div>
the base twig div style form_row block defined in this link below:
{% block form_row %} {% spaceless %} <div> {{ form_label(form) }} {{ form_errors(form) }} {{ form_widget(form) }} </div> {% endspaceless %} {% endblock form_row %}
so, thoughts put necessary divs in, , hard code necessary class entries (i.e. in main div) pass 'attr' value form_label, form_errors , form_widget sections. i've taken out form_errors now, don't deep it. here's tried:
{% form_theme form _self %} {% block form_row %} {% spaceless %} <div class="control-group"> {{ form_label(form, 'test label name', { 'attr': {'class': 'control-label'} }) }} <div class="controls"> {{ form_widget(form) }} {{ form_errors(form) }} </div> </div> {% endspaceless %} {% endblock form_row %}
the problem, though, no matter try, form_label extension not use "control-label" class (and should according source code append if there's existing ones, "required"). here's when view source of rendered page:
<div class="control-group"> <label for="form_rsa_id" class="required">test label name</label> <div class="controls"> <input type="number" id="form_rsa_id" name="form[rsa_id]" required="required" /> </div> </div>
as can see, class="required" there , taken base form object attributes, should class="required control-label", it's not.
kinda @ loss here, documentation (as source) states 1 should use notation "form_label(view, label, variables)". link docs here.
i think need use label_attr
rather attr
.
Comments
Post a Comment