奏鸣曲管理列表字段模板被忽略 [英] Sonata Admin List Field Template is Ignored

查看:37
本文介绍了奏鸣曲管理列表字段模板被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 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'])
    ;
}

这篇关于奏鸣曲管理列表字段模板被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆