EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Trying to override layout.html.twig and other templates

Open arukado-sama opened this issue 11 years ago • 34 comments

Hello!

I just updated the bundle and my override on the layout.html.twig file but I can't make it working. I tried at different locations :

  • app/Resources/views/easy_admin/ (documentation)
  • app/Resources/views/easy_admin/default/
  • app/Resources/EasyAdmin/views/
  • app/Resources/EasyAdmin/views/default/
  • app/Resources/EasyAdminBundle/views/
  • app/Resources/EasyAdminBundle/views/default/

But none of these is working.

Thanks in advance!

arukado-sama avatar Apr 27 '15 10:04 arukado-sama

The correct directory is app/Resources/EasyAdminBundle/views/, the file name is layout.html.twig, and you have to clear your cache when first using this feature, according to the docs

For the others (default and easy_admin), this behavior is not yet released, but it'll be soon, please be patient :smile:

Pierstoval avatar Apr 27 '15 10:04 Pierstoval

Sadly this isn't working anymore for me. I tried at this location too, I'm trying again now and I cleared my cache :cry:

arukado-sama avatar Apr 27 '15 10:04 arukado-sama

@arukado-sama the main problem is that you have caught us in the middle of a big change.

Right now, overriding a template is possible but boring. You have to use Symfony's inheritance mechanism (the custom template should be defined at app/Resources/EasyAdmin/views/ and you have to "destroy" the cache contents (a rm -fr app/cache/* is the best in this case).

However, very soon you'll be able to use a much more powerful and simple override mechanism. This is explained in the Chapter 10 of the documentation. But this is only available in the dev version of this bundle. If you are using a stable version, this won't work. Very soon I'll publish a new stable version and you'll be able to use this feature.

javiereguiluz avatar Apr 27 '15 11:04 javiereguiluz

I also tried at app/Resources/EasyAdmin/views/, this worked fine before the update (this is what I used before) but now this isn't working anymore (and I deleted all caches), don't know why (or maybe I forgot something but I already checked all my files).

arukado-sama avatar Apr 27 '15 11:04 arukado-sama

@arukado-sama OK, then it must be a bug. Just two quick questions:

  1. Are you using the latest stable version of the bundle?
  2. When you say "it doesn't work", you mean some error happens or it just displays the default template without letting you override it?

Thanks.

javiereguiluz avatar Apr 27 '15 11:04 javiereguiluz

My site is actually using the default template of the bundle, the override isn't working.

arukado-sama avatar Apr 27 '15 11:04 arukado-sama

@arukado-sama OK thanks. I'm going to look into it.

javiereguiluz avatar Apr 27 '15 11:04 javiereguiluz

Thanks for your help (and your work, your bundle is fantastic)!

arukado-sama avatar Apr 27 '15 11:04 arukado-sama

I'm using the dev-master version of the bundle, maybe it's the real cause (and if it's the case you can close this thread). I'll wait for the stable version.

arukado-sama avatar Apr 27 '15 12:04 arukado-sama

I've tested the following:

$ symfony demo
$ composer require javiereguiluz/easyadmin-bundle
Enable the bundle in AppKernel and impor routes in app/config/routing.yml

Now, if I create just a custom layout.html.twig template, it doesn't work:

app/Resources/EasyAdminBundle/
└── views
    └── default.html.twig

If I create a list.html.twig template, it works (it overrides the default list template):

app/Resources/EasyAdminBundle/
└── views
    └── list.html.twig

If I define the two custom templates:

app/Resources/EasyAdminBundle/
└── views
    ├── default.html.twig
    └── list.html.twig

When I put the following in the list.html.twig template:

{% extends '@EasyAdmin/default.html.twig' %}

The application uses my custom default.html.twig.

I still don't understand why, but the Symfony inheritance works almost always ... but for the deafult template it only works if it's explicitly used by a custom template.

Fortunately we'll soon merge the new inheritance mechanism and we'll silently deprecate this Symfony stuff.

javiereguiluz avatar Apr 27 '15 13:04 javiereguiluz

Wow, so this really was a bug! Waiting for the update now, thanks again!

arukado-sama avatar Apr 27 '15 14:04 arukado-sama

While we merge the new feautre, I'm reopening this issue just in case some visitor knows the cause of the error and wants to help us solve it. Thanks!

javiereguiluz avatar Apr 27 '15 14:04 javiereguiluz

I've just released the new 1.4.0 version of this bundle. Since overriding the layout.html.twig template is now possible in lots of simple ways, I'm closing this issue as fixed. But if you think is not fixed at all or have problems with the new version, please reopen it. Thanks!

javiereguiluz avatar May 01 '15 10:05 javiereguiluz

I want to reopen this issue, the override on the layout in app/Ressources/views/easy_admin is working like a charm now but I can't override "show" and "edit" twig files for an entity.

I tried with:

  • app/Ressources/views/easy_admin/edit.html.twig
  • app/Ressources/views/easy_admin/EntityName/edit.html.twig

I didn't try with a "default" folder but I don't think it will work. My goal is to customize buttons at the end of the "show" and "edit" forms, don't know if these templates are the solution.

Sorry if I'm wrong on something, I'm a Symfony beginner.

arukado-sama avatar May 04 '15 08:05 arukado-sama

The views you are trying to override are the correct ones, I'm gonna test the configuration to see whether it works or not with v1.4.0. Stay tuned :)

Pierstoval avatar May 04 '15 09:05 Pierstoval

I tried on two different back-ends, and it works for me. I could override each main template (list, edit, new, show) , so I don't get what could be happening...

Maybe @javiereguiluz or @ogizanagi can test on their own envs ?

Edit: what is your environment ? (php version, OS ...)

Pierstoval avatar May 04 '15 18:05 Pierstoval

I'm using Eclipse with php 5.5, on Debian. I'll try again today.

arukado-sama avatar May 05 '15 07:05 arukado-sama

Try to dump the templates paths generated by the processEntityTemplates method in the EasyAdminExtension class.

For instance, right in this class, try to dump this:

dump(
    $applicationTemplateDir.'/easy_admin/'.$entityName.'/'.$templateName.'.html.twig',
    $applicationTemplateDir.'/easy_admin/'.$templateName.'.html.twig'
);

And see the output.

Pierstoval avatar May 05 '15 07:05 Pierstoval

It gave me this error:

UndefinedFunctionException in EasyAdminExtension.php line 402: Attempted to call function "dump" from namespace "JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection".

arukado-sama avatar May 05 '15 08:05 arukado-sama

You can use var_dump instead of dump if you don't use the Symfony Debug bundle nor the VarDumper component :smiley:

Pierstoval avatar May 05 '15 09:05 Pierstoval