PHPackages                             ibrand/laravel-theme - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. ibrand/laravel-theme

ActiveLibrary[Templating &amp; Views](/categories/templating)

ibrand/laravel-theme
====================

Laravel 5 Themes: Asset &amp; Views folder per theme. Theme inheritance. Blade integration and more...

1247[1 issues](https://github.com/iyoyo/laravel-theme/issues)PHP

Since Jul 28Pushed 8y ago2 watchersCompare

[ Source](https://github.com/iyoyo/laravel-theme)[ Packagist](https://packagist.org/packages/ibrand/laravel-theme)[ RSS](/packages/ibrand-laravel-theme/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Description
-----------

[](#description)

[![Laravel](https://camo.githubusercontent.com/7d48a347cda33127449307a1ba24bdebf76d226c4f2a1585285c8e968f2666a9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d352e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](http://laravel.com)[![License](https://camo.githubusercontent.com/30597ff9a350144f03bffdd9183e16468e0b3ca1193e1d08591d992622738d55/687474703a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://tldrlegal.com/license/mit-license)[![Build Status](https://camo.githubusercontent.com/0dfb95de9042f827b97027581fb3b3ac2d32b22efcd18a5c73df74ebde5eee2b/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696761737465722f6c61726176656c2d7468656d652e737667)](https://travis-ci.org/igaster/laravel-theme)[![Downloads](https://camo.githubusercontent.com/bf9e6f5fd35335e192a0588b48ae439e270ab0e501ca6aadef9ec483abea08be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696761737465722f6c61726176656c2d7468656d652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/igaster/laravel-theme)

This is a package for the Laravel 5 Framework that adds basic support for managing themes. It allows you to seperate your views &amp; your assets files in seperate folders, and supports for theme extending! Awesome :)

Features:

- Views &amp; Asset separation in theme folders
- Theme inheritance: Extend any theme and create Theme hierarchies (WordPress style!)
- Integrates [Orchestra/Asset](http://orchestraplatform.com/docs/3.0/components/asset) to provide Asset dependencies managment
- Your App &amp; Views remain theme-agnostic. Include new themes with (almost) no modifications

#### For Laravel 5.0 &amp; 5.1, please use the [v1.0.x branch](https://github.com/igaster/laravel-theme/tree/v1.0)

[](#for-laravel-50--51-please-use-the-v10x-branch)

Table of contents
=================

[](#table-of-contents)

- [How it Works](#how-it-works)
- [Installation](#installation)
- [Define Themes](#defining-themes)
- [Extend Themes](#extending-themes)
- [Work with Themes](#working-with-themes)
- [Build your Views](#building-your-views)
- [setTheme middleware](#settheme-middleware-laravel-52)
- [Parametric filenames](#parametric-filenames)
- [Vendor Paths (Package Development)](#handling-vendor-paths-eg-for-package-development)
- [Custom Error Pages](#custom-error-pages)
- [Assets Management](#assets-management-optional)
- [Assets Dependencies](#assets-dependencies)

How it works
------------

[](#how-it-works)

Very simple, you create a folder for each Theme in 'resources/views' and keep all your views separated. The same goes for assets: create a folder for each theme in your 'public' directory. Set your active theme and you are done. The rest of your application remains theme-agnostic©, which means that when you `View::make('index')` you will access the `index.blade.php` from your selected theme's folder. Same goes for your assets.

Installation
------------

[](#installation)

install with

```
composer require "igaster/laravel-theme"

```

Add the service provider in `app/config/app.php`, `Providers` array:

```
igaster\laravelTheme\themeServiceProvider::class,

```

also edit the `Facades` array and add:

```
'Theme' => igaster\laravelTheme\Facades\Theme::class,

```

Almost Done. You can optionally publish a configuration file to your application with

```
php artisan vendor:publish --provider="igaster\laravelTheme\themeServiceProvider"

```

That's it. You are now ready to start theming your applications!

Defining themes
---------------

[](#defining-themes)

Heads up: Defining a theme is completely optional. You may not touch the config file as long as the defaults fits you! If you want more control then you can define your themes in the `themes` array in [config/themes.php](https://github.com/igaster/laravel-theme/blob/master/src/config.php). The format for every theme is very simple:

```
// Select a name for your theme
'theme-name' => [

    /*
    |--------------------------------------------------------------------------
    | Theme to extend. Defaults to null (=none)
    |--------------------------------------------------------------------------
    */
    'extends'       => 'theme-to-extend',

    /*
    |--------------------------------------------------------------------------
    | The path where the view are stored. Defaults to 'theme-name'
    | It is relative to 'themes_path' ('/resources/views' by default)
    |--------------------------------------------------------------------------
    */
    'views-path'    => 'path-to-views',

    /*
    |--------------------------------------------------------------------------
    | The path where the assets are stored. Defaults to 'theme-name'
    | It is relative to laravels public folder (/public)
    |--------------------------------------------------------------------------
    */
    'asset-path'    => 'path-to-assets',

    /*
    |--------------------------------------------------------------------------
    | Custom configuration. You can add your own custom keys.
    | Retrieve these values with Theme::config('key'). e.g.:
    |--------------------------------------------------------------------------
    */
    'key'           => 'value',
],
```

all settings are optional and can be omitted. Check the example in the configuration file... If you are OK with the defaults then you don't even have to touch the configuration file. If a theme has not been registered then the default values will be used!

Extending themes
----------------

[](#extending-themes)

You can set a theme to extend an other. When you are requesting a view/asset that doesn't exist in your active theme, then it will be resolved from it's parent theme. You can easily create variations of your theme by simply overriding your views/themes that are different.

All themes fall back to the default laravel folders if a resource is not found on the theme folders. So for example you can leave your common libraries (jquery/bootstrap ...) in your `public` folder and use them from all themes. No need to duplicate common assets for each theme!

Working with Themes
-------------------

[](#working-with-themes)

The default theme can be configured in the `theme.php` configuration file. Working with themes is very straightforward. Use:

```
Theme::set('theme-name');        // switch to 'theme-name'
Theme::get();                    // retrieve current theme's name
Theme::current();                // retrieve current theme's object
Theme::config('key');            // read current theme's configuration value for 'key'
Theme::configSet('key','value'); // assign a key-value pair to current theme's configuration
```

You are free to create your own implementation to set a Theme via a ServiceProvider, or a Middleware, or even define the Theme in your Controllers.

Building your views
-------------------

[](#building-your-views)

Whenever you need the url of a local file (image/css/js etc) you can retrieve its path with:

```
Theme::url('path-to-file')
```

The path is relative to Theme Folder (NOT to public!). For example, if you have placed an image in `public/theme-name/img/logo.png` your Blade code would be:

```

```

When you are referring to a local file it will be looked-up in the current theme hierarchy, and the correct path will be returned. If the file is not found on the current theme or its parents then you can define in the configuration file the action that will be carried out: `THROW_EXCEPTION` | `LOG_ERROR` as warning (Default) | `ASSUME_EXISTS` assumes the file does exist and returns the path | `IGNORE` completely.

Some useful helpers you can use:

```
Theme::js('file-name')
Theme::css('file-name')
Theme::img('src', 'alt', 'class-name', ['attribute' => 'value'])
```

'setTheme' middleware (Laravel 5.2+)
------------------------------------

[](#settheme-middleware-laravel-52)

A [helper middleware](https://github.com/igaster/laravel-theme/blob/master/src/Middleware/setTheme.php) is included out of the box if you want to define a Theme per route. To use it:

First register it in `app\Http\Kernel.php`:

```
protected $routeMiddleware = [
    // ...
    'setTheme' => \igaster\laravelTheme\Middleware\setTheme::class,
];
```

Now you can apply the middleware to a route or route-group. Eg:

```
Route::group(['prefix' => 'admin', 'middleware'=>'setTheme:ADMIN_THEME'], function() {
    // ... Add your routes here
    // The ADMIN_THEME will be applied.
});
```

For a more advanced example check demo application: [Set Theme in Session](https://github.com/igaster/laravel-theme-demo)

Parametric filenames
--------------------

[](#parametric-filenames)

You can include any configuration key of the current theme inside any path string using *{curly brackets}*. For example:

```
Theme::url('jquery-{version}.js')
```

if there is a `"version"` key defined in the theme's configuration it will be evaluated and then the filename will be looked-up in the theme hierarchy. (e.g: many commercial themes ship with multiple versions of the main.css for different color-schemes, or you can use [language-dependent assets](https://github.com/igaster/laravel-theme/issues/17))

Handling Vendor paths (eg for Package Development)
--------------------------------------------------

[](#handling-vendor-paths-eg-for-package-development)

When you are namespacing your views then Laravel will look up for view files into the `vendor` folder of the active theme:

```
view('VENDOR_NAME::viewName'); //  \theme_Path\vendor\VENDOR_NAME\viewName.blade.php
```

You can optionaly set a list of vendors in each theme's configuration that will be loaded from the theme's root rather from the 'vendor' directory:

```
'theme-name' => [

    /*
    |--------------------------------------------------------------------------
    | An array of vendors to load from the root of the theme rather than vendor/
    | e.g. view('backend::menu.main') would normally look for following path
    | \path\to\theme\views\vendor\backend\menu\main.blade.php
    | if the below array contained the vendor 'backend' view('backend::menu.main')
    | will instead look in \path\to\theme\views\backend\menu\main.blade.php
    | non-listed vendors will still look in \vendor\...
    |--------------------------------------------------------------------------
    */
    'vendor-as-root'    => ['name', 'of', 'vendors'],

    // ....
]
```php

Now you can:

```php
view('VENDOR_NAME::viewName'); //  \theme_Path\VENDOR_NAME\viewName.blade.php
```

Custom Error Pages
------------------

[](#custom-error-pages)

Sure! Create a folder 'errors' in your theme folder and place 404.blade.php etc. Original error pages will be overidden per theme!

Assets Management (Optional)
----------------------------

[](#assets-management-optional)

This package provides integration with [Orchestra/Asset](http://orchestraplatform.com/docs/3.0/components/asset) component. All the features are explained in the official documentation. If you don't need the extra functionality you can skip this section. Orchestra/Asset is NOT installed along with this package - you have to install it manually.

To install Orchestra\\Asset you must add it in your composer.json (see the [Official Documentation](https://github.com/orchestral/asset)):

```
"orchestra/asset": "~3.0",
"orchestra/support": "~3.0",

```

and run `composer update`. Then add the Service Providers in your Providers array (in `app/config/app.php`):

```
Orchestra\Asset\AssetServiceProvider::class,
Collective\Html\HtmlServiceProvider::class,

```

Add the Asset facade in your `aliases` array:

```
'Asset' => Orchestra\Support\Facades\Asset::class,

```

Now you can leverage all the power of Orchestra\\Asset package. However the syntax can become quite cumbersome when you are using Themes + Orchestra/Asset, so some Blade-specific sugar has been added to ease your work. Here how to build your views:

In any blade file you can require a script or a css:

```
@css('filename')
@js('filename')
@jsIn('container-name', 'filename')

```

Please note that you are just defining your css/js files but not actually dumping them in html. Usually you only need write your css/js declaration in one place on the Head/Footer of you page. So open your master layout and place:

```
{!! Asset::styles() !!}
{!! Asset::scripts() !!}
{!! Asset::container('container-name')->scripts() !!}

```

exactly where you want write your declarations.

Assets dependencies
-------------------

[](#assets-dependencies)

This is an [Orchestra/Asset](http://orchestraplatform.com/docs/3.0/components/asset) feature explained well in the official documentation. Long story short:

```
@css ('filename', 'alias', 'depends-on')
@js  ('filename', 'alias', 'depends-on')

```

and your assets dependencies will be auto resolved. Your assets will be exported in the correct order. The biggest benefit of this approach is that you don't have to move all your declerations in your master layout file. Each sub-view can define it's requirements and they will auto-resolved in the correct order with no doublications. Awesome! A short example:

```
@js  ('jquery.js',    'jquery')
@js  ('bootstrap.js', 'bootsrap', jquery)

```

FAQ:
----

[](#faq)

##### Is this package compatible with AWS?

[](#is-this-package-compatible-with-aws)

Yes with one exception: If you are building Theme hierarcies, asset's will not be looked up on the parent theme. Performing file searching on a remote repository is not the best practice. Should be addressed in a future version... However Blade templates auto-discovery works fine since they are local files.

##### What about external assets (eg CDN)?

[](#what-about-external-assets-eg-cdn)

Link directly to your external assets. Every url that starts with http(s) will not be proccesed by default.

##### Can I place my themes in a different path than Laravel's views folder?

[](#can-i-place-my-themes-in-a-different-path-than-laravels-views-folder)

Yes. Set the `themes_path` option in `themes.php` configuration file to any path. However the default Laravel views path will be used as a fallback when a view is requested and can not be located in any other folder.

##### How do I change the public path?

[](#how-do-i-change-the-public-path)

Rebind Laravel's 'path.public'. [(More info)](https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5)

##### I'm editing a view but I don't see the changes

[](#im-editing-a-view-but-i-dont-see-the-changes)

Laravel is compiling your views every-time you make an edit. A compiled view will not recompile unless you make any edit to your view. You can manually clear compiled views with `artisan view:clear`.Keep this in mind while you are developing themes...

###  Health Score

17

↓

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/05a4dd937f49471fe1d2cb4da6445668df23b2ad2422789b3aaed3ef9459c377?d=identicon)[shjchen](/maintainers/shjchen)

---

Top Contributors

[![chenbidepro](https://avatars.githubusercontent.com/u/9166101?v=4)](https://github.com/chenbidepro "chenbidepro (6 commits)")

### Embed Badge

![Health badge](/badges/ibrand-laravel-theme/health.svg)

```
[![Health](https://phpackages.com/badges/ibrand-laravel-theme/health.svg)](https://phpackages.com/packages/ibrand-laravel-theme)
```

###  Alternatives

[mustache/mustache

A Mustache implementation in PHP.

3.3k44.6M291](/packages/mustache-mustache)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[whitecube/nova-flexible-content

Flexible Content &amp; Repeater Fields for Laravel Nova.

8053.0M25](/packages/whitecube-nova-flexible-content)[mopa/bootstrap-bundle

Easy integration of twitters bootstrap into symfony2

7042.9M33](/packages/mopa-bootstrap-bundle)[limenius/react-bundle

Client and Server-side react rendering in a Symfony Bundle

3871.2M](/packages/limenius-react-bundle)[nicmart/string-template

StringTemplate is a very simple string template engine for php. I've written it to have a thing like sprintf, but with named and nested substutions.

2101.7M30](/packages/nicmart-string-template)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
