title: Customizing Symfony2 forms
body: <p>I recently started using Symfony2 framework. <br>I already apologize for any incorrect terminology I will be using.</p>
  
  <p>I would like to customize how forms are presented in my application.</p>
  
  <p>More specifically, in my Twig file I am rendering the entire form with</p>
  
  <pre><code>{{ form(forms) }}
  </code></pre>
  
  <p>I would like to customize the layout of the form. I know that each row of the form can be expanded as</p>
  
  <pre><code>{{ form_start(forms) }}
  
  //...
  &lt;div&gt;
      {{ form_label(forms.field) }}
      {{ form_errors(forms.field) }}
      {{ form_widget(forms.field) }}
  &lt;/div&gt;
  //...
  
  {{ form_end(forms) }}
  </code></pre>
  
  <p>With the form written in this format I could add the needed customization to the layout.</p>
  
  <p>Here is the problem: my form does not have a pre-defined number of rows, but these depend on some values stored in the database. What I would like to do in my Twig is something like this</p>
  
  <pre><code>{{ form_start(forms) }}
  
  {% for field in forms %}
  &lt;div&gt;
      {{ form_label(forms.field) }}
      {{ form_errors(forms.field) }}
      {{ form_widget(forms.field) }}
  &lt;/div&gt;
  {% endfor %}
  
  {{ form_end(forms) }}
  </code></pre>
  
  <p>Unfortunately, this for loop does not work.
  I also looked into (<a href="http://symfony.com/doc/2.5/cookbook/form/form_customization.html" rel="nofollow">How to Customize Form Rendering</a>), but I think this does not suit my case (does it?).</p>
  
  <p>Any suggestion?<br>
  Thank you in advance for your help.</p>