Skip to content

Commit

Permalink
some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Dec 11, 2014
1 parent 6f3ef09 commit 06bcb61
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions cookbook/form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ we talk about next!).

.. caution::

You have to create **both** ``addTag`` and ``removeTag`` methods,
otherwise the form will still use ``setTag`` even if ``by_reference`` is ``false``.
You have to create **both** ``addTag`` and ``removeTag`` methods,
otherwise the form will still use ``setTag`` even if ``by_reference`` is ``false``.
You'll learn more about the ``removeTag`` method later in this article.

.. sidebar:: Doctrine: Cascading Relations and saving the "Inverse" side
Expand Down Expand Up @@ -729,20 +729,20 @@ the relationship between the removed ``Tag`` and ``Task`` object.
updated (whether you're adding new tags or removing existing tags) on
each Tag object itself.

.. _cookbook-form-collections-custom-prototype
.. _cookbook-form-collections-custom-prototype:

Rendering a Custom Prototype
----------------------------

Most of the time the provided prototype will be sufficient for your needs
and does not need to be changed. But if you are in the situation were
you need to have a complete custom prototype, you can render it yourself:
and does not need to be changed. But if you are in the situation were you
need to have a complete custom prototype, you can render it yourself:

.. configuration-block::

.. code-block:: html+jinja

<!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.twig -->
{# app/Resources/views/Task/prototypeTask.html.twig #}
data-prototype="{% filter escape %}
{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig'
with { 'task': form.task.get('prototype') }
Expand All @@ -751,7 +751,7 @@ you need to have a complete custom prototype, you can render it yourself:

.. code-block:: html+php

<!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.php -->
<!-- app/Resources/views/Task/prototypeTask.html.php -->
data-prototype="<?php
$prototype = $view->render(
'AcmeTaskBundle:Task:prototypeTask.html.php',
Expand All @@ -761,7 +761,8 @@ you need to have a complete custom prototype, you can render it yourself:
echo $view->escape($prototype);
?>"

To be not confused let's have a look how the prototype-template might look like.
To be not confused, have a look at the following example to see how the prototype
template might look like:

.. configuration-block::

Expand All @@ -779,29 +780,29 @@ To be not confused let's have a look how the prototype-template might look like.
<td><?php echo $view['form']->widget($task->getDueDate()) ?></td>
</tr>

The included template contains the markup used for the prototype.
This way you can not only easily structure your prototype-markup,
you can also use this markup to render the
contents of the collection when it already holds items:
The included template contains the markup used for the prototype. This way,
you can not only easily structure your prototype-markup, but you can also
use this markup to render the contents of the collection when it already contains
items:

.. configuration-block::

.. code-block:: html+jinja

{% for task in tasks %}
{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig'
{% include 'task/prototypeTask.html.twig'
with { 'form': form.task.vars.form }
%}
{% endfor %}

.. code-block:: html+php

<?php foreach ($tasks as $task) ?>
<?php echo $view->render('AcmeTaskBundle:Task:prototypeTask.html.php', array('form' => $form->task->vars->form)); ?>
<?php endforeach; ?>
<?php echo $view->render('task/prototypeTask.html.php', array('form' => $form->task->vars->form)); ?>
<?php endforeach ?>

This makes sure the displayed items are the same as the newly inserted
from the prototype.
This ensures that the displayed items are the same as the newly inserted ones
based on the prototype.

.. _`Owning Side and Inverse Side`: http://docs.doctrine-project.org/en/latest/reference/unitofwork-associations.html
.. _`JSFiddle`: http://jsfiddle.net/847Kf/4/

0 comments on commit 06bcb61

Please sign in to comment.