amaxlab/backend-design-bundle
composer require amaxlab/backend-design-bundle
config/bundles.php (or AppKernel.php for older Laravel/Symfony versions):
return [
// ...
Knp\Bundle\MenuBundle\KnpMenuBundle::class,
Mopa\Bundle\BootstrapBundle\MopaBootstrapBundle::class,
AmaxLab\Bundle\BackendDesignBundle\BackendDesignBundle::class,
];
{% extends "BackendDesignBundle::base.html.twig" %}
php artisan assets:install --symlink
npm run dev # or `php artisan assetic:dump` for Assetic
php artisan cache:clear
Create a simple admin page (resources/views/admin/dashboard.html.twig):
{% extends "BackendDesignBundle::base.html.twig" %}
{% block content %}
<h1>{{ page_title }}</h1>
<p>Welcome to the backend!</p>
{% endblock %}
Override page_title in your controller:
return $this->render('admin/dashboard.html.twig', [
'page_title' => 'Dashboard',
]);
Leverage Twig’s block system to customize sections without rewriting the entire template:
{% block before_main_header %}
<div class="alert alert-info">Custom header content</div>
{% endblock %}
{% block aside_navbar_nav %}
<ul class="nav navbar-nav">
<li><a href="{{ path('admin_users') }}">Users</a></li>
<li><a href="{{ path('admin_posts') }}">Posts</a></li>
</ul>
{% endblock %}
Use KnpMenuBundle for dynamic menus (define in config/menus.yml):
main_menu:
items:
dashboard:
label: Dashboard
uri: '#'
users:
label: Users
uri: 'admin_users'
Render in Twig:
{{ knp_menu_render('main_menu', { 'depth': 1 }) }}
Enable in config/packages/backend_design.yaml:
backend_design:
gravatar: true
Use in templates:
<img src="{{ gravatar(user.email, 50) }}" alt="User Avatar">
Override KnpPaginator templates:
# config/packages/knp_paginator.yaml
knp_paginator:
template:
pagination: BackendDesignBundle:Pagination:sliding.html.twig
Render paginated results:
{{ knp_pagination_render(page) }}
Extend CSS/JS blocks:
{% block stylesheets %}
{{ parent() }} {# Include parent styles #}
<link rel="stylesheet" href="{{ asset('css/custom.css') }}">
{% endblock %}
Asset Compilation:
assetic/assetic-bundle is installed and configured.php artisan assets:install --symlink
php artisan cache:clear && php artisan config:clear
Twig Template Paths:
BackendDesignBundle::base.html.twig. Directly extending base.html.twig in templates/ will break inheritance.{{ parent() }} to include parent block content when overriding.Bootstrap Version:
mopa/bootstrap-bundle). For Bootstrap 4/5, manually override CSS/JS or fork the bundle.Gravatar HTTPS:
true as the 5th parameter:
{{ gravatar(user.email, 50, 'g', 'mm', true) }}
MenuBundle Deprecation:
KnpMenuBundle is outdated. For modern Laravel, consider symfony/ux-menu-maker-bundle or manually render menus.{% block debug %}{% endblock %} to inspect variables.php artisan assets:install if missing.php artisan cache:clear
php artisan config:clear
Customize Layout:
base.html.twig in templates/ to modify the entire structure.body_end.Add New Blocks:
{% block custom_sidebar %}{% endblock %}).Modify Bootstrap Components:
_navbar.html.twig in templates/BackendDesignBundle/ (create the directory if missing).Integrate with Laravel Mix:
public/ and updating Twig paths:
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
Localization:
@lang directives.// In a service
$cache->remember("gravatar_{$email}_{$size}", 3600, function() use ($email, $size) {
return gravatar($email, $size);
});
How can I help you explore Laravel packages today?