Global Symfony twig form_themes switching

问题描述 投票:0回答:0

我想用 form_table_layout 覆盖默认的 form_div_layout

(在docs中:类型:字符串数组默认值:['form_div_layout.html.twig'])

我的 config/packages/twig.yaml 是

twig:
    form_themes: ['form/form_table_layout.html.twig']
    default_path: '%kernel.project_dir%/templates'

我将 vendor/symfony/twig-bridge/Resources/views/form/form_table_layout.html.twig 复制到 templates/form/form_table/form_table_layout.html.twig

{% use "form_div_layout.html.twig" %}

{%- block form_row -%}
    {%- set widget_attr = {} -%}
    {%- if help is not empty -%}
        {%- set widget_attr = {attr: {'aria-describedby': id ~"_help"}} -%}
    {%- endif -%}
    <tr{% with {attr: row_attr} %}{{ block('attributes') }}{% endwith %}>
        <td>
            {{- form_label(form) -}}
        </td>
        <td>
            {{- form_errors(form) -}}
            {{- form_widget(form, widget_attr) -}}
            {{- form_help(form) -}}
        </td>
    </tr>
{%- endblock form_row -%}

(etc)

期望的结果:表格采用表格布局。现实:他们仍然在 div 布局中。

调试:配置树枝显示

    form_themes:
    - form_div_layout.html.twig
    - form/form_table_layout.html.twig

文件路径正确:

file templates/form/form_table_layout.html.twig
templates/form/form_table_layout.html.twig: HTML document, ASCII text

缓存:清除并重新启动服务器没有帮助...

可能是什么问题或者我不明白 Symfony 主题的工作方式?

php symfony symfony-forms symfony6
© www.soinside.com 2019 - 2024. All rights reserved.