Symfony-以生成的形式添加文本 [英] Symfony - Add text in generated form
问题描述
我想做一些非常简单的事情,但是我不知道该如何管理.我有一个表格:
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
文本字段和description
文本字段之间)插入"一些文本(例如<p>my Text</p>
).表单是使用表单构建器工具生成的.我已经尝试过类似的事情:
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) }}
For more more information on how you can customize form rendering, please see the forms chapter in the Symfony documentation.
这篇关于Symfony-以生成的形式添加文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!