@@ -120,18 +120,25 @@ not be immediately clear, but they're incredibly powerful. Whenever you
120
120
render any part of a form, the block that renders it makes use of a number
121
121
of variables. By default, these blocks live inside `form_div_layout.html.twig `_.
122
122
123
- Look at the ``generic_label `` as an example:
123
+ Look at the ``form_label `` as an example:
124
124
125
125
.. code-block :: jinja
126
126
127
- {% block generic_label %}
127
+ {% block form_label %}
128
+ {% if not compound %}
129
+ {% set label_attr = label_attr|merge({'for': id}) %}
130
+ {% endif %}
128
131
{% if required %}
129
- {% set attr = attr|merge({'class': attr.class|default('') ~ ' required'}) %}
132
+ {% set label_attr = label_attr|merge({'class': (label_attr.class|default('') ~ ' required')|trim}) %}
133
+ {% endif %}
134
+ {% if label is empty %}
135
+ {% set label = name|humanize %}
130
136
{% endif %}
131
- <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>{{ label|trans }}</label>
132
- {% endblock %}
137
+ <label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>{{ label|trans({}, translation_domain) }}</label>
138
+ {% endblock form_label %}
133
139
134
- This block makes use of 3 variables: ``required ``, ``attr `` and ``label ``.
140
+ This block makes use of several variables: ``compound ``, ``label_attr ``, ``required ``,
141
+ ``label ``, ``name `` and ``translation_domain ``.
135
142
These variables are made available by the form rendering system. But more
136
143
importantly, these are the variables that you can override when calling ``form_label ``
137
144
(since in this example, you're rendering the label).
@@ -162,4 +169,4 @@ to see what options you have available.
162
169
{# does **not** work - the variables are not recursive #}
163
170
{{ form_widget(form, { 'attr': {'class': 'foo'} }) }}
164
171
165
- .. _`form_div_layout.html.twig` : https://github.com/symfony/symfony/blob/2.0 /src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
172
+ .. _`form_div_layout.html.twig` : https://github.com/symfony/symfony/blob/2.1 /src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
0 commit comments