Installation Add the package via Composer:
composer require agg/theme-bundle-modern
Register the bundle in config/bundles.php (Symfony 4+):
return [
// ...
Agg\ModernThemeBundle\ModernThemeBundle::class => ['all' => true],
];
Basic Configuration Publish the default config (if needed):
php bin/console modern-theme:install
Update config/packages/modern_theme.yaml to define your theme structure:
modern_theme:
themes_dir: '%kernel.project_dir%/themes'
default_theme: 'default'
First Use Case: Overriding Bundle Templates
Create a theme directory (e.g., themes/default) and mirror the bundle’s template structure (e.g., AggModernThemeBundle:Default:index.html.twig → themes/default/AggModernThemeBundle/Default/index.html.twig).
Override a template by extending it in your theme:
{% extends 'AggModernThemeBundle:Default:index.html.twig' %}
{% block title %}Custom Title{% endblock %}
config/packages/modern_theme.yaml:
modern_theme:
themes:
- { name: 'admin', parent: 'default' }
- { name: 'frontend', parent: 'admin' }
modern-theme:switch command to activate a theme:
php bin/console modern-theme:switch frontend
ModernThemeBundle\Twig\ThemeExtension to dynamically set themes via logic (e.g., user role):
// src/Twig/AppThemeExtension.php
public function getTheme(): string {
return $this->user->hasRole('ADMIN') ? 'admin' : 'default';
}
config/packages/twig.yaml:
twig:
extensions:
- App\Twig\AppThemeExtension
themes/{theme}/assets/ and reference them in Twig:
{{ asset('bundles/moderntheme/default/css/style.css') }}
config/packages/framework.yaml:
framework:
assets:
version: 'unique-%kernel.environment%'
themes/{theme}/FOSUserBundle/.themes/{theme}/SonataAdminBundle/CRUD/).// src/EventListener/ThemeListener.php
public function onThemeSwitch(ThemeEvent $event) {
$this->cacheClearer->clear($event->getTheme());
}
services.yaml:
services:
App\EventListener\ThemeListener:
tags:
- { name: 'kernel.event_listener', event: 'modern_theme.switch', method: 'onThemeSwitch' }
Template Path Priority
php bin/console debug:config modern_theme
Caching Issues
php bin/console cache:clear
php bin/console assetic:dump --watch
Asset Path Conflicts
asset() with full paths:
{{ asset('themes/default/assets/css/style.css') }} {# Not 'bundles/...' #}
Deprecated Symfony 2 Syntax
twig.config.name instead of twig.bundles.{{ asset_url }} with {{ asset }}.Missing Documentation
php bin/console debug:config modern_theme
php bin/console debug:twig
twig:
debug: '%kernel.debug%'
Custom Theme Loader
Override ModernThemeBundle\Loader\ThemeLoader to support non-filesystem themes (e.g., database-driven themes).
Theme Compiler Pass
Extend ModernThemeBundle\DependencyInjection\Compiler\ThemePass to add theme-specific services.
Event Dispatcher
Extend ModernThemeBundle\Event\ThemeEvent to add custom events (e.g., theme.validate).
Twig Runtime
Replace ModernThemeBundle\Twig\ThemeRuntime to customize theme resolution logic.
How can I help you explore Laravel packages today?