Today I needed to add a custom class to textarea field, to achieve TinyMCE field rendering (with help of http://symfony2bundles.org/stfalcon/TinymceBundle). It wasn’t such straightforward like I thought… I tried:

But it threw exception, that attribute “class” is undefined, so I need to solve it in other way. Thank god I use Twig, so I tried form theming (in template with form). Only thing you need to do is to find out html ID of the textarea field (in my case: wowo_bundle_newsletterbundle_newslettertype_mailing_body). Then you need to add a “_” on the front and “_widget” on the end and class=”tinymce” is there for you.

The solution is simple and powerful, Symfony2 has proven its quality again :-)

UPDATE 19.10.2011
As Florian and Stloyd mentioned in comments, setting custom class can be done in elegant way, which ain’t included in the documentation yet.

UPDATE 29.10.2011

After my contribution, “attr” element is now documented in official Symfony2 docs http://symfony.com/doc/current/reference/forms/types/field.html

Autor

Wojciech Sznapka:
Programming passionate, focused on web technologies with more than 9 years in the industry. On daily basis he designs systems, chooses solutions and implements them. His main areas of interest are software architecture, big data, data mining and Internet of Things.
Google +