Add a specific CSS-class to Symfony2 form

后端 未结 1 1076
南笙
南笙 2021-01-27 12:54

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.

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-27 13:05

    When you render a widget, you can add class with name foo, like this:

    {{ form_widget(form.name, {'attr': {'class': 'foo'}}) }}
    

    If you want to add class foo to form element (tag), then you can use the same syntax:

    {{ form(form, { 'attr': {'class': 'foo'} }) }}
    

    Check out official documentation.

    0 讨论(0)
提交回复
热议问题