Member-only story

Load Stimulus Controllers in Symfony EasyAdmin

Stefan Pöltl
3 min readFeb 18, 2025

I had the use case to enable drag and drop sorting in an EasyAdmin user interface. I want to reuse stimulus controllers I already coded on the Crud index page and take advantage of the simplicity of the Asset Mapper component.

Install Symfony and EasyAdmin

composer create-project symfony/skeleton:"7.2.x" my_project_directory
cd my_project_directory
composer require webapp

composer require easycorp/easyadmin-bundle

Boot Stimulus in the Admin

In order to dynamically load the Stimulus controller as you are used to, we must first create an entry point:

Path: assets/admin.js

import './bootstrap.js';

Add admin.js as entrypoint to your importmap.php in the project root

return [
'app' => [
'path' => './assets/app.js',
'entrypoint' => true,
],
'admin' => [
'path' => './assets/admin.js',
'entrypoint' => true,
],

Now we need to load the import map globally in EasyAdmin by overriding the EasyAdmin layout template:

Path: templates/bundles/EasyAdminBundle/layout.html.twig

{% extends '@!EasyAdmin/layout.html.twig' %}
{% block importmap %}
{{ parent() }}
{{ importmap('admin') }}
{% endblock %}

That’s it, now you can use all your Stimulus controllers in EasyAdmin!

Stefan Pöltl
Stefan Pöltl

Responses (1)

Write a response

If you want to load some AssetMapper entry for all backend pages, there's no need to override the layout template. You can add the following to your Dashboard class:
public function configureAssets(): Assets
{
return…