Skip to content

Fixed documentation of collection prototype #1484

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

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 8 additions & 4 deletions cookbook/form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ new "tag" forms. To render it, make the following change to your template:

.. code-block:: html+jinja

<ul class="tags" data-prototype="{{ form_widget(form.tags.get('prototype')) | e }}">
<ul class="tags" data-prototype="{{ form_widget(form.tags.getVar('prototype')) | e }}">
Copy link
Member

Choose a reason for hiding this comment

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

the recommended syntax to access properties in Twig is form.tags.vars.prototype, which is working since 2.0 and did not changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I will update it accordingly, but clearly the documentation was lacking.

Thanks

...
</ul>

.. code-block:: html+php

<ul class="tags" data-prototype="<?php echo $view->escape($view['form']->row($form['tags']->get('prototype'))) ?>">
<ul class="tags" data-prototype="<?php echo $view->escape($view['form']->row($form['tags']->getVar('prototype'))) ?>">
...
</ul>

Expand All @@ -329,15 +329,19 @@ new "tag" forms. To render it, make the following change to your template:

.. tip::

The ``form.tags.get('prototype')`` is form element that looks and feels just
The ``form.tags.getVar('prototype')`` is form element that looks and feels just
like the individual ``form_widget(tag)`` elements inside our ``for`` loop.
This means that you can call ``form_widget``, ``form_row``, or ``form_label``
on it. You could even choose to render only one of its fields (e.g. the
``name`` field):

.. code-block:: html+jinja

{{ form_widget(form.tags.get('prototype').name) | e }}
{{ form_widget(form.tags.getVar('prototype').name) | e }}

.. versionadded:: 2.1
Prototype is accessed as ``form.tags.getVar('prototype')`` instead of ``form.tags.get('prototype')`` in Symfony 2.1


On the rendered page, the result will look something like this:

Expand Down
6 changes: 3 additions & 3 deletions reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ you need is the JavaScript:
{# ... #}

{# store the prototype on the data-prototype attribute #}
<ul id="email-fields-list" data-prototype="{{ form_widget(form.emails.get('prototype')) | e }}">
<ul id="email-fields-list" data-prototype="{{ form_widget(form.emails.getVar('prototype')) | e }}">
{% for emailField in form.emails %}
<li>
{{ form_errors(emailField) }}
Expand Down Expand Up @@ -295,11 +295,11 @@ collection field:

.. code-block:: jinja

{{ form_row(form.emails.get('prototype')) }}
{{ form_row(form.emails.getVar('prototype')) }}

.. code-block:: php

<?php echo $view['form']->row($form['emails']->get('prototype')) ?>
<?php echo $view['form']->row($form['emails']->getVar('prototype')) ?>

Note that all you really need is the "widget", but depending on how you're
rendering your form, having the entire "form row" may be easier for you.
Expand Down