2 instances of the same embedded form with Symfony & Twig
<p>I'm looking to display 2 instances of the same form inside another form with twig but I can't figure out how.</p>

<p>Here my first form:</p>

<pre><code>/**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    // build form
    $builder
        -&gt;add('contenu', 'text', array(
            'attr'                  =&gt;  array('maxlength' =&gt; 255),
            'empty_data'            =&gt;  "Question par défaut"
        ))
        -&gt;add('file', 'file', array(
            'attr'                  =&gt;  array('accept' =&gt; "image/png, image/jpeg")
        ))
        -&gt;add('contenuQuestion', 'collection', array(
              'type'                =&gt;  new QuizzReponseType(), // here the embedded form
              'allow_add'           =&gt;  true,
              'allow_delete'        =&gt;  true,
              'cascade_validation'  =&gt;  true,
         ))
    ;
}
</code></pre>

<p>with in the entity:</p>

<pre><code>/**
 * @ORM\ManyToMany(targetEntity="OC\QuizzBundle\Entity\QuizzReponse", cascade={"remove", "persist"})
 */
private $contenuQuestion;

function __construct() {
    $this-&gt;contenuQuestion = new ArrayCollection();
}
</code></pre>

<p>Here the embedded form:</p>

<pre><code>/**
 * @param FormBuilderInterface $builder
 * @param array $options
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    // build form
    $builder
        -&gt;add('contenu', 'text', array(
            'attr'                  =&gt;  array('maxlength' =&gt; 50),
            'empty_data'            =&gt;  "Réponse par défaut"
        ))
        -&gt;add('file', 'file', array(
            'attr'                  =&gt;  array('accept' =&gt; "image/png, image/jpeg")
        ))
    ;
}
</code></pre>

<p>The problem is in my view. I want to have 2 instances of the embedded form but the collection seems empty.</p>

<p>It's working well with only one embedded form (NB: my first form is also inside another form but it's not relevant for my question):</p>

<pre><code>// embedded form content field
{{ form_widget(form.contenuQuizz.vars.prototype.contenuQuestion.vars.prototype.contenu) }}
</code></pre>

<p>And I'm looking to do something like that:</p>

<pre><code>// embedded form1 content field
{{ form_widget(form.contenuQuizz.vars.prototype.contenuQuestion.0.vars.prototype.contenu) }}

// embedded form2 content field
{{ form_widget(form.contenuQuizz.vars.prototype.contenuQuestion.1.vars.prototype.contenu) }}
</code></pre>

<p>It looks like the problem is that the collection is not initialized but I'm not sure.</p>

<p>Is there a way to do that ? (with twig and not JavaScript if possible)</p>

<p>Thanks in advance,</p>

<p>Maugun</p>