Symfony 2:在表单构建器中使用Twig扩展

Symfony 2:在表单构建器中使用Twig扩展

问题描述:

I need to change the way a value or label is formatted with a custom filter. However, I need to do this from the form builder rather than in the twig template itself. In other words, when I build my form in the abstract type class, I need to be able to apply specific formatting.

Here is one application where this is needed:

Labels assigned to form elements are based on the database table field names. I need to be able to change how those labels are rendered, such as title case, or upper case, etc.

What's the best way of doing this?

Thanks!

我需要更改使用自定义过滤器格式化值或标签的方式。 但是,我需要从表单构建器而不是在twig模板本身中执行此操作。 换句话说,当我在抽象类型类中构建表单时,我需要能够应用特定的格式。 p>

这是一个需要它的应用程序: p> \ n

分配给表单元素的标签基于数据库表字段名称。 我需要能够更改这些标签的呈现方式,例如标题大小写或大写等。 p>

这样做的最佳方式是什么? p> \ n

谢谢! p> div>

You can create a custom form field type, that extend from choice or entity field type. Then you can customize the template for the field applying filters or whatever you want.