title: How to use existing widget form template blocks
body: <p>I am creating custom Twig form template blocks to do some special rendering.</p>
  
  <p>I have been unable, so far, to use some of the built-in form blocks. Specifically, and of the <code>{{ *_widget() }}</code> blocks.</p>
  
  <p><strong>Example:</strong></p>
  
  <p>Declare a new Twig function.  </p>
  
  <pre><code>/* src/SiteBundle/Library/TwigExtension.php - Bundle-specific Twig extension */
  ...
  public function getFunctions
  {
    $ret = [
      new \Twig_SimpleFunction( 'wwui_myBlock', null, ['node_class'=&gt;'Symfony\Bridge\Twig\Node\RenderBlockNode, 'is_safe'=&gt;['html']] )
    ];
    return $ret;
  }
  </code></pre>
  
  <p>The extension is registered in the service.yml file and is obviously recognized since there are no errors about the wwui_myBlock function being undefined.</p>
  
  <p>Define the Twig block.  </p>
  
  <pre><code>{# src/SiteBundle/Resources/views/Form/fields.html.twig - Custom form blocks #}
  {% block wwui_myBlock %}
    &lt;div class="formRow form-group-xs clearfix"&gt;
      &lt;div class="col-xs-1"&gt;&lt;/div&gt;
      {%- set label_attr = label_attr|merge({class: (label_attr.class|default('') ~ ' col-xs-2' )|trim}) -%}
      {{ form_label( form ) }}
      &lt;div class="col-xs-9"&gt;
        {{ choice_widget( form ) }}
      &lt;/div&gt;
    &lt;/div&gt;
  {% endblock wwui_myBlock %}
  </code></pre>
  
  <p>In the page template.</p>
  
  <pre><code>{# Page-specific template #}
  ...
    {{ form_start( form ) }}
      ...
      {{ wwui_myBlock( form.options ) }} {# options is a choice with radio buttons. #}
      ...
    {{ form_end( form ) }}
  </code></pre>
  
  <p>When this page is rendered an exception is thrown:
  <code>The function "choice_widget" does not exist in SiteBundle:Form:fields.html.twig at line 62</code></p>
  
  <p>My <code>fields.html.twig</code> file "uses" <code>bootstrap_3_horizontal_layout.html.twig</code>. That file "uses" <code>bootstrap_3_layout.html.twig</code> which, in turn, "uses" Twig's default <code>form_div_layout.html.twig</code>. </p>
  
  <p>Why can't my custom block see <code>choice_widget</code> which is defined in <code>form_div_layout.html.twig</code>?</p>