Jelajahi Sumber

[TwigBundle] Add a template block to render CollectionField fields

ornicar 14 tahun lalu
induk
melakukan
f667b6928f

+ 8 - 0
src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php

@@ -5,6 +5,7 @@ namespace Symfony\Bundle\TwigBundle\Extension;
 use Symfony\Component\Form\Form;
 use Symfony\Component\Form\FieldGroupInterface;
 use Symfony\Component\Form\FieldInterface;
+use Symfony\Component\Form\CollectionField;
 use Symfony\Bundle\TwigBundle\TokenParser\FormThemeTokenParser;
 use Symfony\Bundle\FrameworkBundle\Templating\HtmlGeneratorInterface;
 
@@ -100,6 +101,13 @@ class FormExtension extends \Twig_Extension
             ));
         }
 
+        if ($field instanceof CollectionField) {
+            return $this->templates['group']->getBlock('collection', array(
+                'collection' => $field,
+                'attributes' => $attributes,
+            ));
+        }
+
         return $this->templates['field']->getBlock('field', array(
             'field'      => $field,
             'attributes' => $attributes,

+ 8 - 0
src/Symfony/Bundle/TwigBundle/Resources/views/form.twig

@@ -20,6 +20,14 @@
     </tr>
 {% endblock field %}
 
+{% block collection %}
+    <table>
+        {% for field in collection %}
+            {{ field|render }}
+        {% endfor %}
+    </table>
+{% endblock collection %}
+
 {% block errors %}
     {% if errors %}
     <ul>