@@ -667,15 +667,42 @@ you need to have a complete custom prototype you can render it yourself:
667
667
668
668
.. code-block :: html+jinja
669
669
670
+ <!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.twig -->
670
671
data-prototype="{% filter escape %}
671
672
{% include 'AcmeTaskBundle:Task: prototypeTask.html.twig'
672
- with { 'form ': form.task.get('prototype') }
673
+ with { 'task ': form.task.get('prototype') }
673
674
%}
674
675
{% endfilter %}"
675
676
676
- The included ``AcmeTaskBundle:Task:prototypeTask.html.twig `` contains the
677
- markup used for the prototype. This way you can not only easily structure
678
- your prototype-markup, you can also use this markup to render the
677
+ .. code-block :: html+php
678
+
679
+ <!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.php -->
680
+ data-prototype="<?php
681
+ $prototype = $view->render(
682
+ 'AcmeTaskBundle:Task: prototypeTask.html.php',
683
+ array('task' => $form->task->get('prototype')
684
+ );
685
+
686
+ echo $view->escape($prototype);
687
+ ?>"
688
+
689
+ To be not confused let's have a look how the prototype-template might look like.
690
+
691
+ .. code-block :: html+jinja
692
+ <tr>
693
+ <td>{{ form_widget(task.task) }}</td>
694
+ <td>{{ form_widget(task.dueDate) }}</td>
695
+ </tr>
696
+
697
+ .. code-block :: html+php
698
+ <tr>
699
+ <td><?php echo $view['form']->widget($task->getTask()) ?></td>
700
+ <td><?php echo $view['form']->widget($task->getDueDate()) ?></td>
701
+ </tr>
702
+
703
+ The included template contains the markup used for the prototype.
704
+ This way you can not only easily structure your prototype-markup,
705
+ you can also use this markup to render the
679
706
contents of the collection when it already holds items:
680
707
681
708
.. code-block :: html+jinja
@@ -686,6 +713,12 @@ contents of the collection when it already holds items:
686
713
%}
687
714
{% endfor %}
688
715
716
+ .. code-block :: html+php
717
+
718
+ <?php foreach ($tasks as $task) ?>
719
+ <?php echo $view->render('AcmeTaskBundle:Task: prototypeTask.html.php', array('form' => $form->task->vars->form)); ?>
720
+ <?php endforeach; ?>
721
+
689
722
This makes sure the displayed items are the same as the newly inserted
690
723
from the prototype.
691
724
0 commit comments