Skip to content

Commit 603e9fa

Browse files
author
daFish
committed
Fixed merge conflict
2 parents b87f1ee + 98b611d commit 603e9fa

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

cookbook/form/form_collections.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,5 +729,71 @@ the relationship between the removed ``Tag`` and ``Task`` object.
729729
updated (whether you're adding new tags or removing existing tags) on
730730
each Tag object itself.
731731

732+
.. _cookbook-form-collections-custom-prototype
733+
734+
Render a custom prototype
735+
-------------------------
736+
737+
Most of the time the provided prototype will be sufficient for your needs
738+
and does not need to be changed. But if you are in the situation were
739+
you need to have a complete custom prototype you can render it yourself:
740+
741+
.. code-block:: html+jinja
742+
743+
<!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.twig -->
744+
data-prototype="{% filter escape %}
745+
{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig'
746+
with { 'task': form.task.get('prototype') }
747+
%}
748+
{% endfilter %}"
749+
750+
.. code-block:: html+php
751+
752+
<!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.php -->
753+
data-prototype="<?php
754+
$prototype = $view->render(
755+
'AcmeTaskBundle:Task:prototypeTask.html.php',
756+
array('task' => $form->task->get('prototype')
757+
);
758+
759+
echo $view->escape($prototype);
760+
?>"
761+
762+
To be not confused let's have a look how the prototype-template might look like.
763+
764+
.. code-block:: html+jinja
765+
<tr>
766+
<td>{{ form_widget(task.task) }}</td>
767+
<td>{{ form_widget(task.dueDate) }}</td>
768+
</tr>
769+
770+
.. code-block:: html+php
771+
<tr>
772+
<td><?php echo $view['form']->widget($task->getTask()) ?></td>
773+
<td><?php echo $view['form']->widget($task->getDueDate()) ?></td>
774+
</tr>
775+
776+
The included template contains the markup used for the prototype.
777+
This way you can not only easily structure your prototype-markup,
778+
you can also use this markup to render the
779+
contents of the collection when it already holds items:
780+
781+
.. code-block:: html+jinja
782+
783+
{% for task in tasks %}
784+
{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig'
785+
with { 'form': form.task.vars.form }
786+
%}
787+
{% endfor %}
788+
789+
.. code-block:: html+php
790+
791+
<?php foreach ($tasks as $task) ?>
792+
<?php echo $view->render('AcmeTaskBundle:Task:prototypeTask.html.php', array('form' => $form->task->vars->form)); ?>
793+
<?php endforeach; ?>
794+
795+
This makes sure the displayed items are the same as the newly inserted
796+
from the prototype.
797+
732798
.. _`Owning Side and Inverse Side`: http://docs.doctrine-project.org/en/latest/reference/unitofwork-associations.html
733799
.. _`JSFiddle`: http://jsfiddle.net/847Kf/4/

0 commit comments

Comments
 (0)