Skip to content

Commit fd433a1

Browse files
committed
Document Twig test "rootform"
1 parent 6d940aa commit fd433a1

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

reference/forms/twig_reference.rst

+24
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,30 @@ array).
217217
218218
<option {% if choice is selectedchoice(value) %} selected="selected"{% endif %} ...>
219219
220+
.. _form-twig-rootform:
221+
222+
rootform
223+
~~~~~~~~
224+
225+
This test will check for sure if the current ``form`` does not have a parent form view.
226+
It would avoid collision and odd behavior when your form has defined a ``parent`` field.
227+
228+
Wrong example if your form has a field named ``parent``:
229+
230+
.. code-block:: jinja
231+
232+
{% if form.parent is null %}
233+
{{ form_errors(form) }}
234+
{% endif %}
235+
236+
Correct example, this will check for the parent form view rather than its ``parent`` field:
237+
238+
.. code-block:: jinja
239+
240+
{% if form is rootform %}
241+
{{ form_errors(form) }}
242+
{% endif %}
243+
220244
.. _`twig-reference-form-variables`:
221245

222246
More about Form Variables

reference/twig_reference.rst

+13
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,19 @@ selectedchoice
750750
Checks if ``selectedValue`` was checked for the provided choice field. Using
751751
this test is the most effective way.
752752

753+
rootform
754+
~~~~~~~~
755+
756+
.. code-block:: twig
757+
758+
{% if form is rootform %}
759+
760+
``form``
761+
**type**: ``FormView``
762+
763+
Checks for sure if the current ``form`` does not have a parent form view. Using
764+
this test is the safest way if your form contains a ``parent`` field.
765+
753766
Global Variables
754767
----------------
755768

0 commit comments

Comments
 (0)