Symfony Twig Form 特定字段的主题 [英] Symfony Twig Form Theming of specific fields

查看:16
本文介绍了Symfony Twig Form 特定字段的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义表单字段类型和一个关联的表单主题.在一页上我有很多这样的字段,但我特别想更改其中一个字段.

有什么方法可以对同一类型(以及在同一文件中)的某些字段进行不同的主题化吗?

一个简化的例子:

form_fields.html.twig:(本地主题文件)

{% block my_dropdown_row %}

{{ form_label(form) }}{{ form_widget(form) }}{{ form_errors(form) }}</div>{% 端块 %}

在我的表单模板中(所有这些字段都具有相同的类型 - my_dropdown

{{ form_row(form.selectionA) }}{{ form_row(form.selectionB) }}{{ form_row(form.selectionC) }}{{ form_row(form.final_selection) }}

如何以不同于其他字段的方式设置最终字段的样式?这些小部件中有很多代码,因此重复越少越好.

解决方案

这个是可以的.方法如下:

http://symfony.com/doc/current/cookbook/form/form_customization.html

I have a custom form field type and an associated form theme for it. On one page I have a lot of these fields, but one of the fields in particular I want to change.

Is there any way to theme certain fields of the same type (and in the same file) differently?

A simplified example:

form_fields.html.twig: (local theming file)

{% block my_dropdown_row %}
<div>
    {{ form_label(form) }}
    {{ form_widget(form) }}
    {{ form_errors(form) }}
</div>
{% endblock %}

In my form template (all these fields have the same type - my_dropdown

{{ form_row(form.selectionA) }}
{{ form_row(form.selectionB) }}
{{ form_row(form.selectionC) }}
{{ form_row(form.final_selection) }}

How can I style the final field differently to the others? There is a lot of code in these widgets so less duplication the better.

解决方案

This can be done. Here is how:

http://symfony.com/doc/current/cookbook/form/form_customization.html

这篇关于Symfony Twig Form 特定字段的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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