Browse Source

[TwigBundle] added a form_row() function

Fabien Potencier 14 years ago
parent
commit
f946355f80
1 changed files with 17 additions and 0 deletions
  1. 17 0
      src/Symfony/Bundle/TwigBundle/Extension/FormExtension.php

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

@@ -73,6 +73,7 @@ class FormExtension extends \Twig_Extension
             'form_errors'  => new \Twig_Function_Method($this, 'renderErrors', array('is_safe' => array('html'))),
             'form_label'   => new \Twig_Function_Method($this, 'renderLabel', array('is_safe' => array('html'))),
             'form_data'    => new \Twig_Function_Method($this, 'renderData', array('is_safe' => array('html'))),
+            'form_row'     => new \Twig_Function_Method($this, 'renderRow', array('is_safe' => array('html'))),
         );
     }
 
@@ -90,6 +91,22 @@ class FormExtension extends \Twig_Extension
         return $form->isMultipart() ? 'enctype="multipart/form-data"' : '';
     }
 
+    /**
+     * Renders a field row.
+     *
+     * @param FieldInterface $field  The field to render as a row
+     */
+    public function renderRow(FieldInterface $field)
+    {
+        if (null === $this->templates) {
+            $this->templates = $this->resolveResources($this->resources);
+        }
+
+        return $this->templates['field_row']->renderBlock('field_row', array(
+            'child'  => $field,
+        ));
+    }
+
     /**
      * Renders the HTML for an individual form field
      *