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:
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!
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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community