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

Document Twig test "rootform" #10022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 22 reference/forms/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,28 @@ array).

<option {% if choice is selectedchoice(value) %} selected="selected"{% endif %} ...>

.. _form-twig-rootform:

rootform
~~~~~~~~

This test will check if the current ``form`` does not have a parent form view.

.. code-block:: twig

{# DON'T DO THIS: this simple check can't differentiate between a form having
a parent form view and a form defining a normal form field called 'parent' #}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- normal
+ nested

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 640e8e5


{% if form.parent is null %}
{{ form_errors(form) }}
{% endif %}

{# DO THIS: this check is always reliable, even if the form defines a field called 'parent' #}

{% if form is rootform %}
{{ form_errors(form) }}
{% endif %}

.. _`twig-reference-form-variables`:

More about Form Variables
Expand Down
14 changes: 14 additions & 0 deletions 14 reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,20 @@ selectedchoice
Checks if ``selectedValue`` was checked for the provided choice field. Using
this test is the most effective way.

rootform
~~~~~~~~

.. code-block:: twig

{% if form is rootform %}

``form``
**type**: ``FormView``

Checks if the given ``form`` does not have a parent form view. This is the only
safe way of testing it because checking if the form contains a field called
``parent`` is not reliable.

Global Variables
----------------

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.