phpsymfonytwigeasyadmin

Display Information with CRUD Controller (EasyAdmin 4 + Symfony 7)


I would like to know if there's a way to include content with a CRUD controller using EasyAdmin 4 with Symfony 7. I've read all documentation and searched on the internet, but I couldn't find any solutions.

For example, I have a CRUD controller for "keywords":

EasyAdmin keyword CRUD controller

And the keywords are related to "works". I know how to filter the keywords list for a given work, and operate accordingly. I would like to know if there's a way to display further information about the selected work when filtering the keywords in the CRUD controller, for example (I did it on Paint):

Desired result

Probably the way EasyAdmin created the templates as modules, allowing the user to replace parts of the forms, there's a solution like that. Any ideas?


Solution

  • It's possible to obtain such result by overriding block main on index.html.twig template. Something like:

    {% extends '@!EasyAdmin/crud/index.html.twig' %}
    
    {% block main %}
        Put your code here.
        {{ parent() }}
    {% endblock %}
    

    The parent() call is needed to display the table after your changes.

    On the CRUD controller, there's the need to inform the override:

    public function configureCrud(Crud $crud): Crud
    {
        return parent::configureCrud($crud)
            ->overrideTemplate('crud/index', 'admin/crud/index.html.twig')
        ;
    }
    

    The file can be anywhere inside templates folder, or if you prefer, use Symfony mechanism to override templates.