momentumstudio / laravel-theme
Allows developers to split views into multiple, switchable themes.
Requires
- php: ^7.2.0
- laravel/framework: ^5.5.0|^6|^7|^8
Requires (Dev)
- momentumstudio/coding-standards: 1.4.5
- orchestra/testbench: ^3.5.0|^4.0.0|^5.0.0|^6.0.0
- phpstan/phpstan: 0.12.42
- phpstan/phpstan-strict-rules: 0.12.5
README
Laravel Theme
This project is licensed MIT.
Laravel Theme by Momentum Studio is a package that allows the developer to create multiple sets of templates that can be switched at runtime. Allowing for users to set their own theme, or simply for trying out a new theme to a select few users.
- Adds your theme path to Laravel's default
ViewFinder
, making sure it can support other theme-related packages. - Uses a simple Facade to set your current theme.
- Config overridable via environment variables or your own config file.
Installation & Usage
Requires
- PHP 7.2+
- Laravel 5.5+
Use Composer to install Laravel Theme as a dependency into your Laravel project:
composer require momentumstudio/laravel-theme
The package will automatically register itself. You can publish the config file with:
php artisan vendor:publish --provider="MomentumStudio\LaravelTheme\LaravelThemeServiceProvider"
Alternatively, you can just set the environment variables in your .env
file:
DEFAULT_THEME=default
THEMES_PATH=themes
This is the contents of the default configuration file:
return [
/**
* Set default theme to be chosen on startup
* Set to `null` to use default views (resources/views)
*/
'default' => env('DEFAULT_THEME', null),
/**
* Set the base directory to find themes
*/
'path' => env('THEMES_PATH', base_path('themes')),
];
You can set default
to null
to keep using resources/views
until you set otherwise at runtime.
Good for importing this package into existing projects.
Then, to set a theme during runtime, call the provided Facade's set
method:
\MomentumStudio\LaravelTheme\Facades\Theme::set('directory-name');
This will then search your themes path for templates matching the name when calling
Laravel's view()
(or equivalent).
For example, setting my theme to mytheme
and calling view('my-view')
will search
themes/mytheme/my-view.blade.php
first before reverting to resources/views/my-view.blade.php
.
Contributing
Please see CONTRIBUTING.md for details about how you can help!