title: Twig: Selecting certain blocks and rendering them
body: <p>I am intergrating the twig templating engine into a PHP application. In particular, I would like to use the twig engine to render forms.</p>
  
  <p>Having had a look at how symfony2 uses twig to render form widgets, they have a huge template file which contains all the widgets like so:</p>
  
  <pre><code>(...)
  {% block password_widget %}
  {% spaceless %}
      {% set type = type|default('password') %}
      {{ block('field_widget') }}
  {% endspaceless %}
  {% endblock password_widget %}
  
  {% block hidden_widget %}
      {% set type = type|default('hidden') %}
      {{ block('field_widget') }}
  {% endblock hidden_widget %}
  
  {% block email_widget %}
  {% spaceless %}
      {% set type = type|default('email') %}
      {{ block('field_widget') }}
  {% endspaceless %}
  {% endblock email_widget %}
  
  {% block test_widget %}
  {% spaceless %}
     &lt;div&gt;
       {{test}}
     &lt;div&gt;
  {% endspaceless %}
  {% endblock test_widget %}
  
  (...)
  </code></pre>
  
  <p>The question I have is how can I "grab" blocks out of this template and render them?</p>
  
  <p>So far, I am able to load the template, and call get blocks to get all the blocks:</p>
  
  <pre><code>twig = new \Twig_Environment($loader, array('cache' =&gt; 'cache'));
  $template = $twig-&gt;loadTemplate('view\form_div_layout.html.twig');
  //var_dump($template-&gt;getBlocks()); //try getting all blocks
  $template-&gt;displayBlock('test_widget', array('test' =&gt; 'test'));
  echo $template-&gt;render();
  </code></pre>
  
  <p>Unfortunately, I am not able to render just the 'test_widget' block in this case. What should I do to retrieve the 'test_widget' block from the template and then insert it into a different template to render the whole form?</p>