加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

forms – Symfony2 / Twig中的表单标记属性

发布时间:2020-12-14 18:32:24 所属栏目:资源 来源:网络整理
导读:当我想为symfony2表单元素添加一些属性时,我可以使用“attr”属性.但是我如何给起始表单标签本身提供一些id / class / style / other? 解决方法 {{ form_widget(form.name,{ 'attr': {'class': 'foo'} }) }} 这是具有类foo的表单窗口小部件的正确语法.换句
当我想为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和/或类来进行样式设置.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读