Tim*_* K. 6 crud parameter-passing symfony twig easyadmin
我想在编辑页面中显示与实体无关的信息。根据官方文档可以用configureResponseParameters-function来解决。
所以我将该功能实现到我的 CRUD 控制器中。
知道为什么吗?
如何将数据传递到我的 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)
| 归档时间: |
|
| 查看次数: |
1646 次 |
| 最近记录: |