kix
kix

Reputation: 3319

Getting form widget name in Symfony2/Twig

So, what I need to do is to output current element's ID in each field_row. What I came to is overriding Symfony's default field_row block with the following code:

{% block field_row %}
{% spaceless %}
<div class="clearfix" id="{{ form.get('name') }}-row">
    {{ form_label(form) }}
    <div class="input"&gt;
        {{ form_widget(form) }}
    </div>
</div>
{% endspaceless %}
{% endblock field_row %}

However, the {{ form.get('name') }} construct seems pretty awkward to me and I'm sure there's a more civilised way of doing this. Anyone?

Upvotes: 3

Views: 5225

Answers (1)

meze
meze

Reputation: 15087

Do you mean the id generated by symfony? then it's just:

{{ id }}

Upvotes: 7

Related Questions