Support the ongoing development of Laravel.io →
Views Blade Packages

Hello everybody,

I want to share my first package: Basic themes support for Laravel 5. Get it here: igaster/laravel-theme

Some features that I think are usefull:

  • Views & Asset seperation in theme folders
  • Theme inheritence: Extend any theme and create Theme hierarcies (WordPress style!)
  • Intergrates with Orchestra/Asset to provide Asset dependencies managment
  • Your App & Views remain theme-agnostic. Include new themes with no modifications

The most important problem I tried to solve is that when I buy a new Theme it has its own folder structure (and css and js might depend on it). So I end with mixxin all assets in public folder. Nightmare! Seperating themes assets (and views if you want) in folders keeps my app nice and tidy!

A short example usage: Supose that you have some themes. This is an example folder structure for the assets:

public
|-baseTheme
|-theme1
|-theme2

declare the themes in theme.php config as:

'themes' => [
    'baseTheme' => [],

    'theme1' => [
        'extends' => 'baseTheme',
    ],

    'theme2' => [
        'extends' => 'baseTheme',
    ],
]

to set a theme (eg load it from a cookie):

Theme::set( Cookie::get('theme') );

In the views you can reference local assets as Theme::url('file-name'). For example each theme might have a 'logo.jpg' file in the img folder. It should be referenced as:

<img src="{{ Theme::url('img\logo.png') }}">

the url that will be retuned will be the full path for the current theme. Note that views are theme-agnostic!

This is only a simple example, as the same logic can be applied for the views...

Cheers!

Last updated 3 years ago.
0

Hi,

nice package!

I'm not so experienced in Laravel, however, in order to hot-switch themes, I tried to change the "set" function in Themes class as follows:

	// Set active theme (by name)
	public function set($themeName){
		$theme = $this->find($themeName);
		$this->activeTheme = $theme;

		$paths = [];
		do {
			$paths[] = $this->defaultViewsPath.'/'.$theme->viewsPath;
		} while ($theme = $theme->getParent());

		Config::set('view.paths', $paths);

        App::rebinding('view.finder', function($app)
        {
            $paths = $app['config']['view.paths'];

            return new FileViewFinder($app['files'], $paths);
        });

        View::setFinder(app('view.finder'));

    }

I don't know if it is a good idea to call App::rebinding outside of a service provider but it seems to work for now. Thanks

Last updated 10 years ago.
0

I've already merged your submition in the latest version.... Thanks!

0

Good! I'm pleased to have been helpful! :)

0

Really good package.

Can we extend more than one theme ?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

igaster igaster Joined 13 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.