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

查看:64
本文介绍了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文本字段和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屋!

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