Skip to content

Commit a4f53b5

Browse files
author
daFish
committed
Added PHP examples.
Added example for prototype template.
1 parent e222ee1 commit a4f53b5

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

cookbook/form/form_collections.rst

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,15 +740,42 @@ you need to have a complete custom prototype you can render it yourself:
740740

741741
.. code-block:: html+jinja
742742

743+
<!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.twig -->
743744
data-prototype="{% filter escape %}
744745
{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig'
745-
with { 'form': form.task.get('prototype') }
746+
with { 'task': form.task.get('prototype') }
746747
%}
747748
{% endfilter %}"
748749

749-
The included ``AcmeTaskBundle:Task:prototypeTask.html.twig`` contains the
750-
markup used for the prototype. This way you can not only easily structure
751-
your prototype-markup, you can also use this markup to render the
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
752779
contents of the collection when it already holds items:
753780

754781
.. code-block:: html+jinja
@@ -759,6 +786,12 @@ contents of the collection when it already holds items:
759786
%}
760787
{% endfor %}
761788

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+
762795
This makes sure the displayed items are the same as the newly inserted
763796
from the prototype.
764797

0 commit comments

Comments
 (0)