Created
October 17, 2011 23:32
-
-
Save cowlby/1294186 to your computer and use it in GitHub Desktop.
Customizing form collections in Symfony2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% block collection_widget %} | |
{% spaceless %} | |
<div class="collection"> | |
{% if prototype is defined %} | |
{% set attr = attr|merge({'data-prototype': block('collection_item_widget') }) %} | |
{% endif %} | |
<div {{ block('widget_container_attributes') }}> | |
{{ form_errors(form) }} | |
<ul> | |
{% for rows in form %} | |
<li> | |
{% set fieldNum = 1 %} | |
{% for row in rows %} | |
<div class="field{{ fieldNum }}"> | |
{{ form_label(row) }} | |
{{ form_widget(row, { 'attr': { 'class': 'test' }}) }} | |
</div> | |
{% set fieldNum = fieldNum + 1 %} | |
{% endfor %} | |
<a class="remove" title="Remove" href="javascript:void()"> | |
<span>Delete</span> | |
</a> | |
<div class="clear"></div> | |
</li> | |
{% endfor %} | |
</ul> | |
{{ form_rest(form) }} | |
</div> | |
<div class="clear"></div> | |
<a class="add" title="Add" href="javascript:void()"> | |
<div style="display: none;"></div> | |
<span>Add</span> | |
</a> | |
</div> | |
<div class="clear"></div> | |
{% endspaceless %} | |
{% endblock collection_widget %} | |
{% block collection_item_widget %} | |
{% spaceless %} | |
<li> | |
{% set fieldNum = 1 %} | |
{% for row in prototype %} | |
<div class="field{{ fieldNum }}"> | |
{{ form_label(row) }} | |
{{ form_widget(row, { 'attr': { 'class': 'test' }}) }} | |
</div> | |
{% set fieldNum = fieldNum + 1 %} | |
{% endfor %} | |
<a class="remove" title="Remove" href="javascript:void()"> | |
<span>Delete</span> | |
</a> | |
<div class="clear"></div> | |
</li> | |
{% endspaceless %} | |
{% endblock collection_item_widget %} |
Thank you so much for this example.
Wow, awesome.
Thanks so much !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just encountered the very same problem with this line 169.
A quick temporary fix was to replace the line 169 with :
{{ widget|default('')|raw }}
Google indicates me you are the only person having this problem as well, due to the fact we use this configuration :
Did you find a way to fix this problem ?