奏鸣曲管理列表字段模板被忽略
我使用的是 Symfony 4.1.1 和 Sonata Admin Bundle 3.35.2.
I'm using Symfony 4.1.1 and Sonata Admin Bundle 3.35.2.
我想对管理员列表视图中的字段使用自定义模板.模板被忽略.我使用 Twig 作为我的模板引擎.
I want to use a custom template for a field in an admin's list view. The template is ignored. I am using Twig as my templating engine.
在管理员中:
# /src/Admin/ImageAdmin.php
protected function configureListFields(ListMapper $listMapper) {
$listMapper
->add('filename', 'string', ['template' => 'list_image.html.twig'])
;
}
模板:
# /templates/list_image.html.twig
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
<img src="{{ value }}" style="width: 200px" />
{% endblock %}
可能有点晚了,但对于像我一样遇到同样问题的每个人 - 我已经通过在 twig.yaml 中创建特定路径来解决它admin-templates,只需创建一个子文件夹 _admin 或尝试使用 'templates/': 'admin' 将您的文件保存在它们所在的位置(尚未测试这种可能性)
Might be a bit late but for everyone who comes across with the same problem like me - I´ve solved it by creating a specific path within twig.yaml for admin-templates, simply create a subfolder _admin or try to use 'templates/': 'admin' to keep your files where they are (haven't tested this possibility)
# /config/packages/twig.yaml
twig:
paths:
'templates/_admin/': 'admin'
# /src/Admin/ImageAdmin.php
protected function configureListFields(ListMapper $listMapper) {
$listMapper
->add('filename', 'string', ['template' => '@admin/list_image.html.twig'])
;
}