Hi guys,
Trying to override the layout.html.twig file in a new Symfony 4 project but having no luck. Im following the documentation here: https://symfony.com/doc/current/bundles/EasyAdminBundle/book/edit-new-configuration.html#overriding-the-default-templates-by-configuration
I have created a new layout.html.twig file in %project_root%/templates and defined the template (by configuration) in packages/easy_admin.yaml
easy_admin:
design:
templates:
layout: '@App/layout.html.twig'
Any Ideas?
Thanks
PHP version - 7.1
Symfony Version - 4.0.1
EasyAdmin Version - 1.17.7
Hi, for me worked layout: 'admin/layout.html.twig' in symfony 3.4, the file is in templates/admin/layout.htm.twig and extends '@EasyAdmin/default/layout.html.twig'
In Symfony 4 does not exists @App Twig namespace (by default), we don't have AppBundle. It should be now relative to the root templates/ directory instead:
easy_admin:
design:
templates:
layout: 'layout.html.twig' # templates/layout.html.twig
However, you have a native TwigBundle convention here (out-of-the-box) without extra configuration:
templates/bundles/EasyAdminBundle/default/layout.html.twig
Perfect, thanks @yceruto 馃憤 - closing
Same issue happens using a custom AdminController.
use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
class AdminController extends BaseAdminController
{
// ...
}
# app/config/routing.yml
easy_admin_bundle:
resource: "@AppBundle/Controller/AdminController.php"
type: annotation
prefix: /admin
namespace App\Controller;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;
class AdminController extends BaseAdminController
{
// ...
}
easy_admin_bundle:
resource: "Controller/AdminController.php"
prefix: /admin
type: annotation
For the copy pasters like me 馃ぃ
# config/packages/easy_admin.yaml
easy_admin:
design:
templates:
layout: 'admin/layout.html.twig'
{# templates/admin/layout.html.twig #}
{% extends '@EasyAdmin/default/layout.html.twig' %}
{% block head_custom_stylesheets %}
{% for css_asset in easyadmin_config('design.assets.css') %}
<link rel="stylesheet" href="{{ asset(css_asset) }}">
{% endfor %}
{{ encore_entry_link_tags('admin') }}
{% endblock head_custom_stylesheets %}
{% block body_custom_javascript %}
{% for js_asset in easyadmin_config('design.assets.js') %}
<script src="{{ asset(js_asset) }}"></script>
{% endfor %}
{{ encore_entry_script_tags('admin') }}
{% endblock body_custom_javascript %}
Most helpful comment
In Symfony 4 does not exists
@AppTwig namespace (by default), we don't haveAppBundle. It should be now relative to the roottemplates/directory instead:However, you have a native TwigBundle convention here (out-of-the-box) without extra configuration: