向 Symfony2 表单添加特定的 CSS 类 [英] Add a specific CSS-class to Symfony2 form
本文介绍了向 Symfony2 表单添加特定的 CSS 类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我还没有找到解决问题的方法.我认为我可以通过 Twig 做到这一点,但我不知道如何做到.我会感谢您的帮助.
I haven't found a solution for the problem yet. I assume that I can do it through Twig, but I don't know how. I'll be thankful for help.
推荐答案
当你渲染一个小部件时,你可以添加名为 foo 的类,如下所示:
When you render a widget, you can add class with name foo, like this:
{{ form_widget(form.name, {'attr': {'class': 'foo'}}) }}
如果你想给表单元素(标签)添加类foo,那么你可以使用相同的语法:
If you want to add class foo to form element (tag), then you can use the same syntax:
{{ form(form, { 'attr': {'class': 'foo'} }) }}
查看官方文档.
这篇关于向 Symfony2 表单添加特定的 CSS 类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文