gpt4 book ai didi

forms - Symfony2/Twig 中的表单标签属性

转载 作者:行者123 更新时间:2023-12-04 10:00:59 24 4
gpt4 key购买 nike

当我想向 symfony2 表单元素添加一些属性时,我可以只使用“attr”属性。但是我怎样才能给起始表单标签本身提供一些 id/class/style/other 呢?

最佳答案

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

这是具有类 foo 的表单小部件的正确语法。 .换句话说,表单中的表单字段。

您可以为 <form> 申请相同的信息标签。

这是通过渲染完成的
{{ form_start(form, { 'attr': {'class': 'foo', 'id': 'bar', ... } }) }}

请参阅 form_start 上的简短文档 here

Renders the start tag of a form. This helper takes care of printing the configured method and target action of the form. It will also include the correct enctype property if the form contains upload fields.



您可能还对表单变量感兴趣。他们被记录在案 here .总而言之,关于您可以使用的所有函数和变量的完整文档 here

我不建议您使用内联样式。只需使用您为表单提供的 ID 和/或类进行样式设置即可。

关于forms - Symfony2/Twig 中的表单标签属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17579070/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com