EasyAdmin3:将附加变量传递给 twig-template (编辑页面)

Tim*_* K. 6 crud parameter-passing symfony twig easyadmin

背景

我想在编辑页面中显示与实体无关的信息。根据官方文档可以用configureResponseParameters-function来解决。

问题

所以我将该功能实现到我的 CRUD 控制器中。

  • 在 INDEX twig 模板上:我可以使用/查找变量
  • 在编辑树枝模板上:我无法使用/找到变量

知道为什么吗?

如何将数据传递到我的 EDIT-twig 模板?非常感谢!

我的文件

PersonCrudController.php

class PersonCrudController extends AbstractCrudController {
    public function configureCrud(Crud $crud): Crud {

        $crud->setFormThemes([
            'mystuff/person_edit_form.html.twig', '@EasyAdmin/crud/form_theme.html.twig'
        ]);

        return $crud;
    }

    public function configureFields(string $pageName): iterable {
        // ...
        yield TextField::new('specialDisplay')->setFormTypeOption('mapped', false);
        // ...
    }

    public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
    {
        $responseParameters->set('testtesttest', '123xyz');
        return $responseParameters;
    }
    // ...
}
Run Code Online (Sandbox Code Playgroud)

mystuff/person_edit_form.html.twig

{% block _Person_specialDisplay_row %}
    {{ testtesttest }} {# throws: Variable "testtesttest" does not exist. #}
    {{ dump() }}       {# cannot find "testtesttest" anywhere in dump #}

    {# ... here comes the rest that is working perfectly ... #}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)