@@ -740,15 +740,42 @@ you need to have a complete custom prototype you can render it yourself:
740
740
741
741
.. code-block :: html+jinja
742
742
743
+ <!-- src/Acme/TaskBundle/Resources/views/Task/prototypeTask.html.twig -->
743
744
data-prototype="{% filter escape %}
744
745
{% include 'AcmeTaskBundle:Task: prototypeTask.html.twig'
745
- with { 'form ': form.task.get('prototype') }
746
+ with { 'task ': form.task.get('prototype') }
746
747
%}
747
748
{% endfilter %}"
748
749
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
752
779
contents of the collection when it already holds items:
753
780
754
781
.. code-block :: html+jinja
@@ -759,6 +786,12 @@ contents of the collection when it already holds items:
759
786
%}
760
787
{% endfor %}
761
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
+
762
795
This makes sure the displayed items are the same as the newly inserted
763
796
from the prototype.
764
797
0 commit comments