使用 Sonata Admin 列表中的自定义列 [英] Use custom column in Sonata Admin list

查看:42
本文介绍了使用 Sonata Admin 列表中的自定义列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Symfony 4.1 创建了一个项目,并安装了 Sonata Admin Bundle.

在我的类别列表中,我尝试添加与类别字段无关的列

所以我做到了

/* Admin/CategoryAdmin.php */受保护的函数 configureListFields(ListMapper $listMapper){$listMapper->addIdentifier('name')->add('test_column', 'string', ['模板' =>'template_test.html.twig',]);}

还有我的模板.

{# templates/template_test.html.twig #}{% 扩展 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}{% 块字段 %}测试{% 结束块 %}

该列已创建,但它是空的.我做错了什么?这是我的测试项目:

在我旧的 Symfony3.4 大项目上,编译的模板与模板相同.

但我还是不知道为什么

解决方案

ad yceruto 在评论中说,我的 twig extends 的表示法不好:

{% 扩展 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

代替

{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

I created a project with Symfony 4.1, and install Sonata Admin Bundle.

In a listing of my categories, I try to add a column which is not related to a field of Category

So I did

/* Admin/CategoryAdmin.php */

protected function configureListFields(ListMapper $listMapper)
{
    $listMapper
        ->addIdentifier('name')
        ->add('test_column', 'string', [
            'template' => 'template_test.html.twig',
        ]);
}

And my template.

{# templates/template_test.html.twig #}

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

{% block field %}
    TEST
{% endblock %}

The column is created, but it's empty. What did I do wrong? Here's my test project: https://github.com/AntoineLemaire/sonata-admin-issue/commits/master

I had a other big project with Symfony 3.4 where it's working with no problem, so I created a fresh projet in 3.4, but I got the same issue.

No error message, juste blank for my column

---------- EDIT -----------

I had a better look, and it seams that the compiled template does not match my template

On my old big Symfony3.4 projet, compiled template is the same as template.

But I still don't know why

解决方案

Ad yceruto said in the comments, the notation of my twig extends was not good:

{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}

instead of

{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

这篇关于使用 Sonata Admin 列表中的自定义列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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