3

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

enter image description here

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

But I still don't know why

Bouffe
  • 770
  • 13
  • 37

2 Answers2

2

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' %}
Bouffe
  • 770
  • 13
  • 37
1

This ist most likely a path problem. The tricky thing is, that the configureList function won't give you any error (other like in configureForm). It displays the column, tries to match a property in your object but left it empty if there is no property. Double-check your path. I think you are pointing to the wrong file path.

You write

{# templates/template_test.html.twig #}

but you point to

'template' => 'template_test.html.twig',

So sonata is looking for app/Resources/view/template_test.html.twig

but your comment say its anywhere in app/Resources/view/templates/template_test.html.twig or somewhere else.

Jim Panse
  • 2,220
  • 12
  • 34