2

I am attempting to customise the markup of a form element in my Symfony form, however I am having difficulty targeting this element alone. I have read this section in the SF cookbook - but I am having difficulty applying it to my situation.

The form_row block that I have extended does what I want it to do, however this applies to all form_rows called in that template - how can I apply it to sizes (which is an array) only?

view.html.twig:

{% form_theme form 'CRMPiccoProductBundle:CourseGuideRow:fields.html.twig' %}

{{ form_row(form.name) }}
{% for size in form.sizes %}
   {{ form_row(size) }}
{% endfor %}

fields.html.twig:

{% block form_row %}
    <td style="width: 75px; border-right: 2px solid #000000;">
        {{ form_widget(form) }}
    </td>
{% endblock %}

My form is called crmpicco_course_guide_row:

/**
 * @return string name
 */
public function getName()
{
    return 'crmpicco_course_guide_row';
}

This results in this markup:

    <td style="width: 75px; border-right: 2px solid #000000;">
    <input type="text" class=" form-control" 
required="required" name="crmpicco_course_guide_row[sizes][0]" 
id="crmpicco_course_guide_row_sizes_0">
    </td>
crmpicco
  • 16,605
  • 26
  • 134
  • 210
  • 1
    Take a look at this: http://symfony.com/doc/current/cookbook/form/form_customization.html#how-to-customize-an-individual-field – Carlos Granados Oct 26 '15 at 19:21

1 Answers1

0

I think you just have to apply your form theme only to the "sizes" child forms.

{% form_theme form.sizes 'CRMPiccoProductBundle:CourseGuideRow:fields.html.twig' %}
Gladhon
  • 211
  • 2
  • 5