title: How to Understand the Variables Available in Custom Twig Form Template for each Input
body: <p>I understand <a href="http://symfony.com/doc/current/cookbook/form/form_customization.html" rel="nofollow noreferrer">how to customize the twig template for forms per the documenation</a>.</p>
  
  <p>But I do not fully understand which variables are available in each block. I've studied the <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig" rel="nofollow noreferrer">original twig form template file</a>, but the scope of variables available in each block is not obvious to me yet. </p>
  
  <p>For example, I followed the <a href="http://symfony.com/doc/current/cookbook/form/form_customization.html#adding-a-required-asterisk-to-field-labels" rel="nofollow noreferrer">tutorial to add an asterisk to the <code>form_label</code> block, if it's required</a>. But I do not want the asterisk if it's a hidden field (obviously... but the tutorials leave that part out). I am told hidden fields cannot ever BE required, but my hidden field required value is evaluating true...</p>
  
  <p>This is how my hidden field is defined:</p>
  
  <pre><code>-&gt;add('timePublish', 'hidden', array(
      'required' =&gt; false
  ))
  </code></pre>
  
  <p>This still gets rendered in the HTML:</p>
  
  <pre><code>&lt;span class="required" title="This field is Required"&gt;*&lt;/span&gt;
  &lt;div id="view_version"&gt;
      &lt;input type="hidden" id="view_version_timePublish" name="view[version][timePublish]" class="form-control"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>So I don't know why that is happening in the first place. But given that it is, I would like to be explicit and skip the asterisk if it's type = hidden.</p>
  
  <p>The <code>required</code> attribute is available in this block, but not the <code>type</code> of input:</p>
  
  <pre><code>{% block form_label %}
  {{ parent() }}
  {% if required is not empty and type != "hidden" %}
      &lt;span class="required" title="This field is Required"&gt;*&lt;/span&gt;
  {% endif %}
  {{ block('form_help') }}
  {% endblock %}
  </code></pre>
  
  <p>Unfortunately, <code>type</code> is not available, and throws an error:</p>
  
  <pre><code>Variable "type" does not exist in GutensiteCmsBundle:Form:fields.html.twig
  </code></pre>
  
  <p>I tried other variations like <code>form.type</code>, <code>form.vars.type</code>, <code>form.attr.type</code>, <code>form.vars.attr.type</code>, and <code>attr.type</code>, but none of these work either...</p>
  
  <p>In addition to helping me understand this one variable name, can someone please reference comprehensive documentation for these variables (or give a summary of how to understand it myself), and help me understand how to dump this data for my own debugging in the future?</p>
  
  <h2>UPDATE</h2>
  
  <p>The hidden input field was not causing the required asterisk to show up. Instead it was the included sub form. I have a primary form type <code>Form/Type/ViewType.php</code> which defines the main form, and includes several sub forms, e.g.</p>
  
  <pre><code>-&gt;add('version', new ViewVersionType(), array(
      'label' =&gt; false,
      'required' =&gt; false
  ))
  </code></pre>
  
  <p>Even though I had <code>'label'=&gt;false</code>, the form_label was still rendering the asterisk. I had to also specify <code>'required'=&gt;false</code> as well and that got rid of the asterisk. That seems really odd to me, that the included form IS allowed to have a required attribute (or at least that it defaults to true).</p>
  
  <h2>Finding the Type</h2>
  
  <p>For Symfony 2.4 you can access type like this: <code>{{ form.vars.block_prefixes.1 }}</code>. This will show 'text', 'choice', etc. (<a href="https://stackoverflow.com/a/18786597/3334390">reference</a>) It's not the HTML input 'type', but rather the symfony form type, so if you define a custom type (like a nested form) it will show the name of that, e.g. 'viewVersion'</p>