Easyadminbundle: Override layout.html.twig Symfony 4

Created on 6 Dec 2017  路  5Comments  路  Source: EasyCorp/EasyAdminBundle

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

Most helpful comment

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

All 5 comments

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.

Old (see here):

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

New

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 %}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ziobudda picture ziobudda  路  4Comments

BigMichi1 picture BigMichi1  路  3Comments

joazvsoares picture joazvsoares  路  4Comments

SirMishaa picture SirMishaa  路  3Comments

seb-jean picture seb-jean  路  3Comments