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

Fixed documentation of collection prototype #1486

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 6 commits into from
Jul 3, 2012
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
Prev Previous commit
Next Next commit
Changed syntax of .getVar('prototype') to .vars.prototype as suggeste…
…d by @stof in PR #1484
  • Loading branch information
lavoiesl committed Jun 21, 2012
commit bc2feb737d10c05be48e08d8ab1951726d26d351
10 changes: 5 additions & 5 deletions 10 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.getVar('prototype')) | e }}">
<ul class="tags" data-prototype="{{ form_widget(form.tags.vars.prototype) | e }}">
...
</ul>

.. code-block:: html+php

<ul class="tags" data-prototype="<?php echo $view->escape($view['form']->row($form['tags']->getVar('prototype'))) ?>">
<ul class="tags" data-prototype="<?php echo $view->escape($view['form']->row($form['tags']->vars['prototype'])) ?>">
Copy link
Member

Choose a reason for hiding this comment

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

this is wrong. For the PHP template, you should document getVar(). If you want to use the same way than Twig, it would be ->getVars()['prototype'], but this only wokrs on PHP 5.4 with the array dereferencing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mmm sorry about that. It was maybe a little too late when I did this…

...
</ul>

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

.. tip::

The ``form.tags.getVar('prototype')`` is form element that looks and feels just
The ``form.tags.vars.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.getVar('prototype').name) | e }}
{{ form_widget(form.tags.vars.prototype.name) | e }}

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

Choose a reason for hiding this comment

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

it already works in 2.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, but we should update the 2.0 doc to show the same so people start writing it like this already. What do you think ?



On the rendered page, the result will look something like this:
Expand Down
6 changes: 3 additions & 3 deletions 6 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.getVar('prototype')) | e }}">
<ul id="email-fields-list" data-prototype="{{ form_widget(form.emails.vars.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.getVar('prototype')) }}
{{ form_row(form.emails.vars.prototype) }}

.. code-block:: php

<?php echo $view['form']->row($form['emails']->getVar('prototype')) ?>
<?php echo $view['form']->row($form['emails']->vars['prototype']) ?>
Copy link
Member

Choose a reason for hiding this comment

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

same issue here for the PHP template


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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.