Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 551a19b

Browse filesBrowse files
committed
minor #10022 Document Twig test "rootform" (yceruto, javiereguiluz)
This PR was merged into the 2.8 branch. Discussion ---------- Document Twig test "rootform" Documents PR symfony/symfony#25236 and closes #8829, sorry for the delay. Commits ------- cf355c9 Reworded the code comments 423bfae Minor reword 740803e Reword fd433a1 Document Twig test "rootform"
2 parents 3e93523 + cf355c9 commit 551a19b
Copy full SHA for 551a19b

File tree

2 files changed

+36
-0
lines changed
Filter options

2 files changed

+36
-0
lines changed

‎reference/forms/twig_reference.rst

Copy file name to clipboardExpand all lines: reference/forms/twig_reference.rst
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ 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 if the current ``form`` does not have a parent form view.
226+
227+
.. code-block:: twig
228+
229+
{# DON'T DO THIS: this simple check can't differentiate between a form having
230+
a parent form view and a form defining a normal form field called 'parent' #}
231+
232+
{% if form.parent is null %}
233+
{{ form_errors(form) }}
234+
{% endif %}
235+
236+
{# DO THIS: this check is always reliable, even if the form defines a field called 'parent' #}
237+
238+
{% if form is rootform %}
239+
{{ form_errors(form) }}
240+
{% endif %}
241+
220242
.. _`twig-reference-form-variables`:
221243

222244
More about Form Variables

‎reference/twig_reference.rst

Copy file name to clipboardExpand all lines: reference/twig_reference.rst
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,20 @@ 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 if the given ``form`` does not have a parent form view. This is the only
764+
safe way of testing it because checking if the form contains a field called
765+
``parent`` is not reliable.
766+
753767
Global Variables
754768
----------------
755769

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.