Inspired by bigecko/laravel-theme. Themes are stored inside default laravel's resources folder
This package requires PHP 7.3 or event 8.* and Laravel 8 or 9.
Currently, supported only for webpack with laravel-mix
.
You can install this package via composer using:
composer require yaap/theme
or manually add line to composer.json
{
"require": {
"yaap/theme": "^4.0"
}
}
Optionally, publish config using artisan CLI (if you want to overwrite default config).
php artisan vendor:publish --provider="YAAP\Theme\ThemeServiceProvider"
return [
/*
|--------------------------------------------------------------------------
| Path to directory with themes
|--------------------------------------------------------------------------
|
| The directory with your themes.
|
*/
'path' => base_path('themes'),
/*
|--------------------------------------------------------------------------
| Path to directory with assets build
|--------------------------------------------------------------------------
|
| The directory with assets build in public directory.
|
*/
'assets_path' => 'themes',
/*
|--------------------------------------------------------------------------
| A pieces of theme collections
|--------------------------------------------------------------------------
|
| Inside a theme path we need to set up directories to
| keep "layouts", "assets" and "partials".
|
*/
'containerDir' => [
'assets' => 'assets',
'lang' => 'lang',
'layout' => 'layouts',
'partial' => 'partials',
'view' => 'views',
],
];
Config in theme folder
return [
/*
|--------------------------------------------------------------------------
| Theme name
|--------------------------------------------------------------------------
|
| Use in assets publishing etc.
|
*/
'name' => '%theme_name%',
/*
|--------------------------------------------------------------------------
| Inherit from another theme
|--------------------------------------------------------------------------
|
| Set up inherit from another if the file is not exists.
|
*/
'inherit' => null,
];
The first time you have to create theme default
structure, using the artisan command:
php artisan theme:create default
In order to seed webpack.mix.js
with custom rules add --with-mix
option
php artisan theme:create default --with-mix
To delete an existing theme, use the command:
php artisan theme:destroy default
Here is an example of the folder structure of project with theme
project-root
├── app/
<...>
├── public/
| ├── index.php
| └── themes/
| └── default/
| ├── js/
| | └── app.js
| ├── css/
| | └── styles.css
| └── images/
| └── icon.png
├── resources/
<...>
├── themes/
| ├── default/
| | ├── assets/
| | ├── lang/
| | ├── layouts/
| | ├── partials/
| | ├── views/
| | | └── hello.blade.php
| | └── config.php
| ├── admin/
| ├── views/
| ├── emails/
| | └── notify.blade.php
| └── hello.blade.php
Theme::init($name)
This will add to views find path:
- themes/{$name}
- themes/{$name}/views
Lang files will be added as well:
- themes/{$name}/lang
View::make('hello');
View::make('emails.notify');
Use laravel mix for assets.
In header
<link rel="stylesheet" href="{{ mix('/themes/default/css/app.min.css') }}"/>
and in footer
<script type="text/javascript" src="{{ mix('/themes/default/js/app.min.js') }}"></script>
@extends('layouts.master')
@include('partials.header')
@section('content')
<section id="main">
<h1>HOME</h1>
</section>
@stop
@include('partials.footer')
You still able to use default View::make('emails.notify')
which is stored outside the themes directory.
Yes! Say hi: hello@hexide-digital.com
We will be happy to work with you! Other work we’ve done
Stay up to date with the latest Vuestic news! Follow us on LinkedIn or Facebook
MIT license.