Skip to content

Instantly share code, notes, and snippets.

@cowlby
Created October 17, 2011 18:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowlby/1293363 to your computer and use it in GitHub Desktop.
Save cowlby/1293363 to your computer and use it in GitHub Desktop.
Customizing form collections in Symfony2
{% block collection_widget %}
{% spaceless %}
{% if prototype is defined %}
{% set attr = attr|merge({'data-prototype': block('collection_item_widget') }) %}
{% endif %}
<div class="collection" {{ block('widget_container_attributes') }}>
{{ form_errors(form) }}
<table>
<thead>
<tr>
<th>Name</th>
<th>Value</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for rows in form %}
block('collection_item_widget')
{% endfor %}
</tbody>
</table>
{{ form_rest(form) }}
<a class="collection_add btn" title="Add" href="#">Add</a>
</div>
{% endspaceless %}
{% endblock collection_widget %}
{% block collection_item_widget %}
{% spaceless %}
<tr>
{% for row in prototype %}
<td>
{{ form_widget(row) }}
</td>
{% endfor %}
<td>
<a class="remove" title="Remove" href="#">Delete</a>
</td>
</tr>
{% endspaceless %}
{% endblock collection_item_widget %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment