Installation
composer require djaney/theming-bundle
Register the bundle in config/app.php under providers:
Djaney\ThemingBundle\ThemingBundle::class,
Define Themes
Configure themes in config/theming.php:
'themes' => [
'base' => 'BaseThemeBundle',
'child' => 'ChildThemeBundle',
],
First Use Case
Override a template in ChildThemeBundle (e.g., Resources/views/base.html.twig).
The bundle will automatically use the child template if it exists, falling back to the base.
Resources/views/ of the child bundle. The bundle merges paths:
ChildThemeBundle/Resources/views/partials/header.html.twig
└─ BaseThemeBundle/Resources/views/partials/header.html.twig (fallback)
{{ parent() }} in child templates to inherit base logic:
{% extends 'base.html.twig' %}
{% block title %}{{ parent() }} - Child Theme{% endblock %}
Djaney\ThemingBundle\ThemeResolverInterface to resolve themes dynamically (e.g., via user preference):
public function resolveTheme(): string {
return request()->user()->preferredTheme ?? config('theming.themes.child');
}
web/css/child.css overrides web/css/base.css).encore.setPublicPath() per theme in webpack.config.js:
if (process.env.THEME === 'child') {
encore.setPublicPath('/build/child');
}
Djaney\ThemingBundle\Twig\ThemingExtension to add theme-specific logic:
public function getThemeAssets(): array {
return [
'css' => asset(mix('css/child.css')),
'js' => asset(mix('js/child.js')),
];
}
php artisan cache:clear
php artisan config:clear
Resources/views/layouts/ vs. Resources/views/layout/).ThemeResolverInterface before ThemingBundle loads in AppServiceProvider@register().storage/logs/laravel.log for missing file errors. Verify:
php artisan vendor:publish --tag=theming-config).ThemeResolverInterface for multi-tenancy or A/B testing:
class TenantThemeResolver implements ThemeResolverInterface {
public function resolveTheme(): string {
return Tenant::current()->theme ?? config('theming.themes.base');
}
}
theming.theme.resolved to log or modify theme resolution:
event(new ThemeResolved($themeName));
Djaney\ThemingBundle\ThemingBundle to add fallback chains (e.g., child → base → default).How can I help you explore Laravel packages today?