Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize widget's ID attribute in Twig

Tags:

Is it possible to customize HTML 'id' attribute in Twig when rendering a widget with {{ form_widget(form.NAME_OF_THE_FIELD) }} ?

Passing {'attr': {'id': 'SOMETHING'}} doesn't work...

Thanks for help!

like image 238
grzechoo Avatar asked Nov 21 '11 14:11

grzechoo


2 Answers

Did you try: {{ form_widget(form.title, { 'id': 'my_custom_id' }) }}?

If this still doesn't work, you could also rely on form customization to handle it. But this could be overkill and may not be the best idea. Check the documentation on form theming for more info.

As I said, maybe there is better way but this is only what I can propose you for now.

Hope this helps.

like image 151
Matt Avatar answered Oct 21 '22 07:10

Matt


{{ form_widget(form.title, { 'attr': {'id': 'my_id'} }) }}

http://symfony.com/doc/current/book/forms.html

I have used it and it works.

like image 34
Ritesh Patadiya Avatar answered Oct 21 '22 08:10

Ritesh Patadiya