title: Symfony twig how to add class to a form row
body: <p>I am building a project in Symfony 2.3 using Twig. I want to add a class to the form row block. I am using a form theme file which contains:</p>
  
  <pre><code>{% block form_row %}
      &lt;div class="form-row"&gt;
          {{ form_label(form) }}
          {{ form_widget(form) }}
          {{ form_errors(form) }}
      &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p>Now some of my form rows I want to add an extra class <code>form-row-split</code>. I can't figure out how to do this properly. The way I have it almost-working is:</p>
  
  <pre><code>{% block form_row %}
      {% set attr = attr|merge({'class': 'form-row' ~ (attr.class is defined ? ' ' ~ attr.class : '') ~ (errors|length &gt; 0 ? ' error' : '')} ) %}
      &lt;div {{ block('widget_container_attributes') }}&gt;
          {{ form_label(form) }}
          {{ form_widget(form) }}
          {{ form_errors(form) }}
      &lt;/div&gt;
  {% endblock %}
  </code></pre>
  
  <p>(Note, I've left the <code>error</code> class logic in there too as that needs to stay).
  Then in the form builder:</p>
  
  <pre><code>$builder
          -&gt;add('first_name', 'text', array(
              'attr' =&gt; array(
                  'class' =&gt; 'form-row-split'
              )
          ));
  </code></pre>
  
  <p>This almost works but it adds this class everywhere and also adds the widget id to the row! </p>
  
  <pre><code>&lt;div id="myform_first_name" class="form-row form-row-split"&gt;
      &lt;label for="myform_first_name"&gt;First name&lt;/label&gt;
      &lt;input id="myform_first_name" class="form-row-split" type="text" name="myform[first_name]"&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I can think of a few potential solutions but none of them are pretty or straight forward. Surely there must be a simple way of doing this?</p>