Personalización de un widget de formulario en Symfony2 / Twig

In my form template:

{% block field_label %}
{% spaceless %}
    <label {{ block('widget_attributes') }}></label>
{% endspaceless %}
{% endblock %}

I need to add some extra class attributes and, of course, display the label (possibly translated). I've found that {{ block('widget_attributes') }} almacena un string of attributes of the actual label.

Any chance to get an array type to easily modify it? Where i can find all block names to customize the appearance to fit my needs? Thanks for helping.

preguntado el 10 de marzo de 12 a las 02:03

1 Respuestas

Nevermind Notepad++ helped me to find the file:

vendor\symfony\src\Symfony\Bridge\Twig\Resources\views

Three types of label defined:

{# Labels #}

{% block generic_label %}
{% spaceless %}
    {% if required %}
        {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
    {% endif %}
    <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
{% endspaceless %}
{% endblock %}

{% block field_label %}
{% spaceless %}
    {% set attr = attr|merge({'for': id}) %}
    {{ block('generic_label') }}
{% endspaceless %}
{% endblock field_label %}

{% block form_label %}
{% spaceless %}
    {{ block('generic_label') }}
{% endspaceless %}
{% endblock form_label %}

respondido 10 mar '12, 03:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.