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
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
Prev Previous commit
Next Next commit
Minor reword
  • Loading branch information
javiereguiluz authored Jul 5, 2018
commit 423bfae89b81cead319273ea1b9c1aef3430e127
12 changes: 5 additions & 7 deletions 12 reference/forms/twig_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,18 @@ array).
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.
This test will check if the current ``form`` does not have a parent form view.

Wrong example if your form has a field named ``parent``:
.. code-block:: twig

.. code-block:: jinja
{# DON'T DO THIS: this code will fail when the form doesn't have a parent
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd like to rephrase this sentence... since in no case this code will fail because the FormView has a public parent property. The problem appears when you have also defined a parent form field. The last one will have priority for Twig due the array access ability.

I'm not sure how to explain it in short though.

Copy link
Member Author

@yceruto yceruto Jul 5, 2018

Choose a reason for hiding this comment

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

I mean... what you expect for form.parent could change depending on whether your form has or not a parent field. If no: you're checking the parent view, if yes: you're checking the parent field

but it defines a normal form field called 'parent' #}

{% 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
{# DO THIS: this code will always work, regardless of the form field names #}

{% if form is rootform %}
{{ form_errors(form) }}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.