Theme support for Laravel 5
Inspired by bigecko/laravel-theme.
Themes are stored inside default laravel's resources folder, (*1)
Installation
Require this package in your composer.json:, (*2)
"yaap/theme": "2.*"
And add the ServiceProvider to the providers array in config/app.php, (*3)
'YAAP\Theme\ThemeServiceProvider',
Publish config using artisan CLI (if you want to overwrite default config)., (*4)
php artisan vendor:publish --tag="config"
You can register the facade in the aliases key of your config/app.php file., (*5)
'aliases' => array(
'Theme' => 'YAAP\Theme\Facades\Theme'
)
Package config
return array(
'path' => base_path('resources/themes'),
'assets_path' => 'assets/themes',
);
Theme config
return array(
'name' => 'default',
'parent_theme' => null,
);
Usage
Structure
โโโ resources/
โโโ themes/
โโโ default/
| โโโ layouts/
โโโ partials/
โโโ views/
| โโโ hello.blade.php
โโโ config.php
โโโ admin/
โโโ views/
| โโโ emails/
| | โโโ notify.blade.php
| โโโ hello.blade.php
|
โโโ lang/
โโโ public/assets/
โโโ themes/
โโโ default/
โโโ css/
| โโโ styles.css
โโโ images/
โโโ icon.png
Create theme with artisan CLI
The first time you have to create theme "default" structure, using the artisan command:, (*6)
php artisan theme:create default
To delete an existing theme, use the command:, (*7)
php artisan theme:destroy default
Init theme
Theme::init($name)
This will add to views find path:
* resources/themes/{$name}
* resources/themes/{$name}/views, (*8)
Making view
View::make('hello');
View::make('emails.notify');
Assets
Assets can be nested too.
Asset url can be automatically with version., (*9)
<link rel="stylesheet" href="{{ Theme::asset('css/styles.css', null, true) }}"/>
<link rel="stylesheet" href="{{ Theme::asset('css/ie.css', null, 'v1') }}"/>
The first one will get version from filemtime, the second one - from params, (*10)
Blade templates
@extends('layouts.master')
@include('partials.header')
@section('content')
<section id="main">
<h1>HOME</h1>
</section>
@stop
@include('partials.footer')
Fallback capability
You still able to use default View::make('emails.notify') which is stored outside the themes directory, (*11)