Symfony - 以生成的形式添加文本 [英] Symfony - Add text in generated form

查看:17
本文介绍了Symfony - 以生成的形式添加文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些非常简单的事情,但我不知道如何管理它.我有一个表格:

I'd like to do something quite simple, but I can't figure out how to manage it. I have a form:

{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

其中有几个文本字段.我想在两个文本字段(比如说 name 文本字段和 <代码>描述文本字段).表单是使用表单生成器工具生成的.我尝试过类似的方法:

There are several text field in it. I'd like to "insert" some text (like <p>my Text</p>) between two text fields (let's say between name text field and description text field). Form are generated with form builder tool. I've tried something like:

$builder
    ->add('stuffName') // works well (text field 1)
    ->add('addedText', 'text', array('label' => 'my Text')) // Trouble here!
    ->add('stuffDescription'); // works well (text field 2)

但它会生成一个文本字段(而不是简单的文本).我不在乎文本是在表单构建器中设置还是直接在树枝模板中设置......只要它在我的两个文本字段之间.有什么想法吗?

But it generates a text field (and not a simple text). I don't care if the text is set in the form builder or directly in twig template... As long as it is between my two text fields. Any idea?

非常感谢!

推荐答案

Symfony 表单只包含个表单域.您想要的任何其他内容都必须由模板添加.

Symfony forms contain only form fields. Any additional content you want has to be added by the template.

这意味着您必须逐个字段地输出表单.例如,您的表单可能如下所示:

This means you'll have to output the form field-by-field. Your form, for example might look like this:

{{ form_start(form) }}
    {{ form_row(form.stuffName) }}

    <p>Your Text</p>

    {{ form_row(form.stuffDescription) }}
{{ form_end(form) }}

有关如何自定义表单呈现的更多信息,请参阅 Symfony 文档中的表单章节.

For more more information on how you can customize form rendering, please see the forms chapter in the Symfony documentation.

这篇关于Symfony - 以生成的形式添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆