title: Symfony2 Nested Collections and the Prototype
body: <p>I have 3 nested form in Symfony2. I won't get into all the code here beacuse it can be long. I'm just gonna show an example of what I want to do here. </p>
  
  <p>So, let's say that <code>Category</code> has a <code>Product</code> and the Product has a <code>Tag</code>.
  Each one of them would be a reusable <code>AbstractType</code>.</p>
  
  <p>This would be the code for the <strong>CategoryType</strong> (I will leave out <code>allow_add</code>, <code>allow_delete</code>, and <code>by_reference</code> for increased readability). </p>
  
  <pre><code>$builder-&gt;add('product', 'collection', array(
      'type' =&gt; new ProductType(),
      'prototype' =&gt; true,
      'prototype_name' =&gt; '__product__'
  ));
  </code></pre>
  
  <p>This would be the <strong>ProductType</strong></p>
  
  <pre><code>$builder-&gt;add('tag', 'collection', array(
      'type' =&gt; TagType(),
      'prototype' =&gt; true, 
      'prototype_name' =&gt; '__tag_name__'
  ));
  </code></pre>
  
  <p><strong>TagType</strong> is not really important here. What I want is render the prototype for these collections in Twig in two <code>divs</code> like this...</p>
  
  <pre><code>&lt;div class="ResourceAttributePrototype" data-product-prototype="{{ form_widget(form.product.vars.prototype)|e  }}"&gt;&lt;/div&gt;
  
  &lt;div class="Prototype" data-tag-prototype="{{ form_widget(form.product.vars.prototype.children['tag'].vars.prototype)|e }}"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The problem is that the first prototype is render in the data attribute, but the second is an empty string. Why?</p>
  
  <p>Also, if anyone has a better idea of how to render nested form collections, Im all ears. I found <a href="https://stackoverflow.com/questions/16487129/symfony2-multiple-nested-forms-prototype">a good example</a> that i followed but it does not work.</p>