【问题标题】:Symfony 5: apply template to all fields of specific custom form typeSymfony 5:将模板应用于特定自定义表单类型的所有字段
【发布时间】:2021-03-25 12:12:46
【问题描述】:

我已经创建了自定义表单类型字段,我不想在每次使用此字段时都为此字段应用自定义主题:{% form_theme form.test 'custom_fields/datalist.html.twig' %}

有没有办法通过在树枝配置等中添加一些东西来将此模板应用于具有这种类型的所有字段?

【问题讨论】:

    标签: php symfony yaml twig symfony5


    【解决方案1】:

    我将此添加到我的 twig.yaml 中:

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

    在模板中我设置了正确的块前缀:{% block datalist_widget %} 现在为每个 DatalistType 字段应用自定义模板。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多