Lamotivo Theme Manager is a Laravel package to manage themes in your application.

It allows you to organize your views and assets in separate directories.

Main features:

  • Separation of views and assets in theme directories.
  • Theme inheritance.
  • Integration with Lamotivo Asset Manager.


Require the package:

composer require lamotivo/themes

Publish a configuration file:

php artisan vendor:publish --provider="Lamotivo\Themes\ThemeServiceProvider" --tag=config


Theme Structure

Default themes location:

  • resources/themes

You are free to set your own location in the themes.php configuration file.

Directory structure for a theme named red:

  • resources/themes/red/views
  • resources/themes/red/assets/js
  • resources/themes/red/assets/css
  • resources/themes/red/assets/public

Views from themes have an advantage over resources/views.

They also override namespaced views.

Using Theme

You may activate a theme using the following:

  • on run time:
  • using the middleware at app\Http\Kernel.php:
protected $middlewareGroups = [
    'web' => [
        // ...

protected $routeMiddleware = [
    // ...
    'theme' => \Lamotivo\Themes\Middleware\UseTheme::class,
  • at the .env file:

Then you may use it in your routes:

    'prefix' => '/red-theme',
    'middleware' => 'theme:red',
], function() {
    // ...

Theme Assets

Theme public assets are located at the public/vendor/themes directory by default. You can override the vendor/themes prefix in the themes.php configuration file.

To access assets from HTML you should create symbolic links to your themes.

Use the themes:link Artisan command to achieve this:

php artisan themes:link

This will create links for each registered theme from public/vendor/themes/* to resources/themes/*/assets/public.

In your Blade views you can use the @theme_url Blade helper:

<img src="@theme_url('some-image.jpg')">

The example above will produce code like that:

<img src="/vendor/themes/red/some-image.jpg">

Sometimes you may want to fetch some asset from a fixed theme like so:

<img src="@theme_url('some-image.jpg', 'winter')">

The example above will produce code like that:

<img src="/vendor/themes/winter/some-image.jpg">

If the active theme extends from another one, assets are also inherited.

Handling JS and CSS/SCSS Assets

By default all JS and CSS assets are placed in the assets/js and assets/css directories relatively to the theme location.

You can use any other structure to your liking.

We use Lamotivo Asset Manager to handle assets.

In your Blade views you can use code like this:

<!DOCTYPE html>
    <!-- ... -->