Skip to content
Sunel Tr edited this page Sep 15, 2015 · 10 revisions

Every page has common layout in a XML file, you can find the files in the package layout folder. You can use the default.xml [here][1] as it is.

To move the files to your application run the following artisan command

$ php artisan vendor:publish --provider="Layout\Provider\LayoutServiceProvider" --tag=layout

This will move the default layout xml files into "resources/layout/layout" folder.

What if we need to change it???

Not a problem at all.You can change the options in the default xml with out touching the file, we will look into that later.

This command will export basic css needed for a page layout

 $ php artisan vendor:publish --provider="Layout\Provider\LayoutServiceProvider" --tag=public

Now in the layout config file add location of your xml files in the 'xml_location'

'xml_location' => [
    __DIR__.'/../resources/layout'
],

Note You can also add multiple xml file location

Now the system will know where to find the layout definitions.


Lets assume we are requesting for home page of the application which has the name "home"

Route::get('/',['as'=>'home',function(){	
	return render();	
}]);

Instead of calling this for the view

  return view('view.name') 

we use this

  return render() 

Next create a xml file with any name

The hierarchy of loading files is based on alphabetical order in that respective folder. So the nodes of file that gets loaded last will have highest priority.

and add the below snippet

<?xml version="1.0"?>
<layout version="0.1.0">
	<home>
		<reference name="content">
            <block class="\Layout\Block" name="home" template="home">
            </block>
        </reference>
    	<reference name="left">
            <block class="\Layout\Block" name="home.left" template="left">
            </block>
        </reference>
        <reference name="right">
            <block class="\Layout\Block" name="home.right" template="right">
            </block>
        </reference>
	</home>
</layout>

Remember to add home.blade.php,left.blade.php,right.blade.php in your view dir.

Note: For this example we are going to use a page which has layout with 3 columns

Save the file.

Note <home> this is the handle that loades the content for the page , to say it fills the placeholders which is defined in the default handle

Now when request for the router with the name 'home'

That's it you will see a fully render page

Note: in the template="home" you can give any template

← Configuration | [1]:https://github.com/sunel/laravel-layout/wiki/default.xml