Package Data | |
---|---|
Maintainer Username: | awjudd |
Maintainer Contact: | contact@andrewjudd.ca (Andrew Judd) |
Package Create Date: | 2013-12-25 |
Package Last Update: | 2016-12-20 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:07:43 |
Package Statistics | |
---|---|
Total Downloads: | 6,092 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 5 |
Total Watchers: | 4 |
Total Forks: | 3 |
Total Open Issues: | 2 |
A quick and easy way to handle different layouts in Laravel 5
In the require
key of composer.json
file add the following
"awjudd/layoutview": "1.2.*"
Run the Composer update command
$ composer update
In your config/app.php
add 'Awjudd\Layoutview\LayoutviewServiceProvider'
to the end of the $providers
array
'providers' => array(
'Illuminate\Foundation\Providers\ArtisanServiceProvider',
'Illuminate\Auth\AuthServiceProvider',
...
'Awjudd\Layoutview\LayoutviewServiceProvider',
),
'aliases' => array(
'App' => 'Illuminate\Support\Facades\App',
'Artisan' => 'Illuminate\Support\Facades\Artisan',
...
'View' => 'Awjudd\Layoutview\Facades\LayoutViewFacade',
),
Setup for Layout View is simple. All you need to do is change the mapping in the aliases array for the "View" to point to the new type.
Once done, the next step for you to do is to configure the namespaces that you want included as well as the priority of the views that are being rendered. To publish the configuration you can do the following:
$ php artisan config:publish awjudd/layoutview
There are two ways to configure what the base and fallback layouts are. The two ways are as follows:
'layout' => array (
/**
* The layout that will be used to fall back on if the selected doesn't exist.
*
* @var string
*/
'fallback' => NULL,
/**
* The layout that will be the first choice to be used.
*
* @var string
*/
'selected' => NULL,
),
View::setSelectedLayout('base layout name');
View::setFallbackLayout('fallback layout name');
Within the configuration file there is a single key. This key is 'namespaces'
. Fill this array with any namesapces that you would like the application to look through the folders of in order to find the best-fitting view.
Please Note The order that the elements are added in this array dictate the order in which they are scanned through for display purposes. Because of this, you will want your most specific namespaces to be listed first.
'namespaces' => array (
/*
* Should always keep a blank one here to search in no namespaces.
*/
'',
),
In order for this to work, this package requires the following folder structure (in short, your layout name is the top level).
./views
./base
./home
./index.blade.php
./fallback
./home
./index.blade.php
./test.blade.php
./layout
./html.blade.php
In this example, "base" and "fallback" are your two possible layouts. If you have "base" as your selected layout, and "fallback" as your fallback view (meaning if one doesn't exist in your main, it will look there next). If you do the following:
View::make('home.index');
It will render the view in 'base/home/index'. However, if you do one that doesn't exist in the base folder, then it will automatically pick up the one from the fallback. Example:
View::make('home.test');
Will render 'fallback/home/test'.
Layout View is free software distributed under the terms of the MIT license
1.1.0:
1.1.1:
Any issues, please report here