-
-
Save cowlby/1294186 to your computer and use it in GitHub Desktop.
{% 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 %} |
When I try to use it with the symfony 2.6 bootstrap form theme, I get "Variable "widget" does not exist in bootstrap_3_layout.html.twig at line 169". The code responsible is below (fourth from bottom). Any idea how to fix this? Thanks.
{% block checkbox_radio_label %}
{% if required %}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' required')|trim}) %}
{% endif %}
{% if parent_label_class is defined %}
{% set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' ' ~ parent_label_class)|trim}) %}
{% endif %}
{% if label is empty %}
{% set label = name|humanize %}
{% endif %}
<label{% for attrname, attrvalue in label_attr %} {{ attrname }}="{{ attrvalue }}"{% endfor %}>
{{ widget|raw }}
{{ label|trans({}, translation_domain) }}
{% endblock checkbox_radio_label %}
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 :
form:
resources: ['bootstrap_3_layout.html.twig' ]
Did you find a way to fix this problem ?
Thank you so much for this example.
Wow, awesome.
Thanks so much !
How can I use collection_widget to render view? Can you please give one simple usage? I am trying to use this for TagCollection in Task and Tag tutorial of Symfony.