bahadir arslan
bahadir arslan

Reputation: 4762

EasyAdmin Using your Own Templates Problem

I am trying to override "new" template for EasyAdmin but system ignores template code. Here is the relevant part of easy_admin.yaml

entities:
       # List the entity class name you want to manage
      Places:
          class: App\Entity\Places
          templates:
              list: 'asdfasdf'

As you see, value of list attribute is invalid but system ignores it and works without error and i can not override the template.

Do you have a suggestion?

Upvotes: 2

Views: 5104

Answers (2)

Jaime Roman
Jaime Roman

Reputation: 989

If you use EasyAdmin 3.x, for that you can overwrite a specific template specifying it in your entity's Controller or you can create your own folder structures like symfony does.

In this example I am overwriting only the edit template for my 'studient' entity, if you want to change all the edits of your project you must do so by creating the folder structure as symfony does.

public function configureCrud(): Crud
{
    return Crud::new()
       
        ->overrideTemplate('crud/edit', 'studient/edit.html.twig')
    ;
}

You can even combine both methods. Suppose that in addition to modifying only the template 'edit' of studient you want to modify the way in which easyadmin displays the flash messages for that you only have to create this structure in your templates folder: "templates\bundles\EasyAdminBundles\flash_messages.html.twig"

I leave the link with the documentation for EasyAdmin 3.x overriding-templates

Upvotes: 1

Evgeny Ruban
Evgeny Ruban

Reputation: 1443

So, as I mentioned in the comment - for some reason easyadmin doesn't give any errors if specified template doesn't exists. So, you just need to place your new template in templates folder, in example, templates/admin/listPlaces.html.twig and then specify correct path in easyadmin's config file, in example:

entities:
    Places:
        class: App\Entity\Places
        templates:
             list: 'admin/listPlaces.html.twig'

Upvotes: 2

Related Questions