如何更改 Symfony 2 / Twig 中的 form_row 行为
默认情况下,form_row(form.name)
呈现为类似以下内容:
<div><label for="form_name" class=" required">Name</label><input type="text" id="form_name" name="form[name]" required="required" maxlength="45" value=""></div>
如何/在哪里可以将 form_row()
的行为更改为例如:
<div class="someClassName"><label for="form_name" class=" required">Name</label></div><div class="someOtherClassName"><input type="text" id="form_name" name="form[name]" required="required" maxlength="45" value=""></div>
By default a form_row(form.name)
is rendered as something like:
<div><label for="form_name" class=" required">Name</label><input type="text" id="form_name" name="form[name]" required="required" maxlength="45" value=""></div>
How/where can I change the behaviour of form_row()
to for example:
<div class="someClassName"><label for="form_name" class=" required">Name</label></div><div class="someOtherClassName"><input type="text" id="form_name" name="form[name]" required="required" maxlength="45" value=""></div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检查此网址: http://symfony .com/doc/2.0/cookbook/form/form_customization.html#cookbook-form-theming-methods
有一段关于自定义 form_row() 的内容。
这是一个简单的例子。默认情况下, form_row() 将创建一个简单的 html 结构,如下所示:
TWIG:
HTML:
因此,根据文档,您可以创建一个新的 twig 模板,并将 class="form_row" 添加到字段和标签周围。将其放在 YourBundle/views/Form/fields.html.twig 中,然后将以下代码放入其中:
在模板文件中,添加以下行:
现在,将使用您创建的该文件中的 form_row 模板,并将返回以下 HTML 代码:
希望有帮助。
You can check this URL: http://symfony.com/doc/2.0/cookbook/form/form_customization.html#cookbook-form-theming-methods
There's a paragraph about customizing form_row().
Here's a simple example. By default, form_row() would create a simple html structure like this:
TWIG:
HTML:
So, according to the docs, you can create a new twig template, and add class="form_row" to surrounding the field and label. Place it in YourBundle/views/Form/fields.html.twig and put the following code in there:
In your template file, add the following line:
Now, the form_row template from that file you created will be used, and will return the following HTML code:
Hope that it helps.