简体   繁体   English

Symfony 5:将模板应用于特定自定义表单类型的所有字段

[英]Symfony 5: apply template to all fields of specific custom form type

I have created custom form type field and I don't want apply custom theme for this field like this: {% form_theme form.test 'custom_fields/datalist.html.twig' %} every time when I use this field.我已经创建了自定义表单类型字段,并且我不想在每次使用此字段时为此字段应用自定义主题: {% form_theme form.test 'custom_fields/datalist.html.twig' %}

Is there any way to apply this template to all fields with this type by adding something to twig config, etc?有没有办法通过向 twig 配置等添加一些内容来将此模板应用于此类型的所有字段?

I added this to my twig.yaml:我将此添加到我的 twig.yaml 中:

form_themes: [
        'custom_fields/datalist.html.twig'
]

In template I set correct block prefix: {% block datalist_widget %} And now for every DatalistType field applied custom template.在模板中,我设置了正确的块前缀: {% block datalist_widget %} 现在为每个 DatalistType 字段应用自定义模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM