@@ -314,5 +314,41 @@ Field Variables
314
314
315
315
.. tip ::
316
316
317
- It's significantly faster to use the :ref: `selectedchoice <form-twig-selectedchoice >`
318
- test instead when using Twig.
317
+ In Twig template, instead of using ``is_selected() ``, it's significantly
318
+ faster to use the :ref: `selectedchoice <form-twig-selectedchoice >` test.
319
+
320
+ Accessing Form Choice Data
321
+ ...........................
322
+
323
+ The ``form.vars `` variable of each choice entry holds data such as whether the
324
+ choice is selected or not. If you need to get the full list of choices data and
325
+ values, use the ``choices `` variable from the parent form of the choice entry
326
+ (which is the ``ChoiceType `` itself) with ``form.parent.vars.choices ``::
327
+
328
+ .. code-block :: html+twig
329
+
330
+ {# `true ` or `false `, whether the current choice is selected as radio or checkbox #}
331
+ {{ form.vars.data }}
332
+
333
+ {# the current choice value (i.e a category name when `'choice_value' => 'name' ` #}
334
+ {{ form.vars.value }}
335
+
336
+ {# a map of `ChoiceView ` or `ChoiceGroupView ` instances indexed by choice values or group names #}
337
+ {{ form.parent.vars.choices }}
338
+
339
+ Following the same advanced example as above (where choices values are entities),
340
+ the ``Category `` object is inside ``form.parent.vars.choices[key].data ``::
341
+
342
+ .. code-block :: html+twig
343
+
344
+ {% block _form_categories_entry_widget %}
345
+ {% set entity = form.parent.vars.choices[form.vars.value].data %}
346
+
347
+ <tr>
348
+ <td>{{ form_widget(form) }}</td>
349
+ <td>{{ form.vars.label }}</td>
350
+ <td>
351
+ {{ entity.name }} | {{ entity.group }}
352
+ </td>
353
+ </tr>
354
+ {% endblock %}
0 commit comments