@@ -132,7 +132,9 @@ good idea to include this in your form tag:
132
132
More about Form Variables
133
133
-------------------------
134
134
135
- For a full list of variables, see: :ref: `reference-form-twig-variables `.
135
+ .. tip ::
136
+
137
+ For a full list of variables, see: :ref: `reference-form-twig-variables `.
136
138
137
139
In almost every Twig function above, the final argument is an array of "variables"
138
140
that are used when rendering that one part of the form. For example, the
@@ -200,6 +202,27 @@ The following variables are common to every field type. Certain field types
200
202
may have even more variables and some variables here only really apply to
201
203
certain types.
202
204
205
+ Assuming you have a ``form `` variable in your template, and you want to reference
206
+ the variables on the ``name `` field, accessing the variables is done by using
207
+ a public ``vars `` property on the :class: `Symfony\\ Component\\ Form\\ FormView `
208
+ object:
209
+
210
+ .. configuration-block ::
211
+
212
+ .. code-block :: html+jinja
213
+
214
+ <label for="{{ form.name.vars.id }}"
215
+ class="{{ form.name.vars.required ? 'required' : '' }}">
216
+ {{ form.name.label }}
217
+ </label>
218
+
219
+ .. code-block :: html+php
220
+
221
+ <label for="<?php echo $view['form']->get('name')->vars['id'] ?>"
222
+ class="<?php echo $view['form']->get('name')->vars['required'] ? 'required' : '' ?>">
223
+ <?php echo $view['form']->get('name')->vars['label'] ?>
224
+ </label>
225
+
203
226
+-----------------+-----------------------------------------------------------------------------------------+
204
227
| Variable | Usage |
205
228
+=================+=========================================================================================+
@@ -228,7 +251,7 @@ certain types.
228
251
| ``label `` | The string label that will be rendered |
229
252
+-----------------+-----------------------------------------------------------------------------------------+
230
253
| ``multipart `` | If ``true ``, ``form_enctype `` will render ``enctype="multipart/form-data" ``. |
231
- | | This only applies to the parent form element. |
254
+ | | This only applies to the root form element. |
232
255
+-----------------+-----------------------------------------------------------------------------------------+
233
256
| ``attr `` | A key-value array that will be rendered as HTML attributes on the field |
234
257
+-----------------+-----------------------------------------------------------------------------------------+
0 commit comments