8000 Document Twig test "rootform" by yceruto · Pull Request #10022 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

Document Twig test "rootform" #10022

< 8000 details class="details-reset details-overlay details-overlay-dark float-right" > 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 1 commit
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
Next Next commit
Document Twig test "rootform"
  • Loading branch information
yceruto committed Jul 5, 2018
commit fd433a16ce4fe15f1040e2a96eab4c6102243701
24 changes: 24 additions & 0 deletions reference/forms/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ array).

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

.. _form-twig-rootform:

rootform
~~~~~~~~

This test will check for sure if the current ``form`` does not have a parent form view.
It would avoid collision and odd behavior when your form has defined a ``parent`` field.

Wrong example if your form has a field named ``parent``:

.. code-block:: jinja

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

Correct example, this will check for the parent form view rather than its ``parent`` field:

.. code-block:: jinja

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

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

More about Form Variables
Expand Down
13 changes: 13 additions & 0 deletions reference/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,19 @@ 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 for sure if the current ``form`` does not have a parent form view. Using
this test is the safest way if your form contains a ``parent`` field.

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

Expand Down
0