Skip to content

Commit 4e8637f

Browse files
daFishxabbuh
daFish
authored andcommitted
Added reusing of prototype template for displaying items from collection.
1 parent 3f6fdd7 commit 4e8637f

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cookbook/form/form_collections.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,18 @@ from the prototype.
805805

806806
But if you are in the situation were you need to have a complete custom prototype you can render it yourself:
807807

808-
.. code-block:: html+jinja
809-
data-prototype="{% filter escape %}{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig' with { 'form': form.task.get('prototype') } %}{% endfilter %}"
808+
.. code-block:: html+jinja
809+
data-prototype="{% filter escape %}{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig' with { 'form': form.task.get('prototype') } %}{% endfilter %}"
810+
811+
The included `AcmeTaskBundle:Task:prototypeTask.html.twig` contains the markup used for the prototype. This way you can not only easily structure your prototype-markup, you can
812+
also use this markup to render the contents of the collection when it already holds items:
813+
814+
.. code-block:: html+jinja
815+
{% for task in tasks %}
816+
{% include 'AcmeTaskBundle:Task:prototypeTask.html.twig' with { 'form': form.task.vars.form } %}
817+
{% endfor %}
818+
819+
This makes sure the displayed items are the same as the newly inserted from the prototype.
810820

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

0 commit comments

Comments
 (0)