UNIX BLOG

Blog for NIX system based administrators

Laravel header footer layout

For using a standart header and footer for every page in Laravel Framework, we need to define a layout.

This article will describe to you, how to setup a layout with header and footer in LARAVEL framework for PHP in 7 STEPS

1 STEP:
Define a layout, make a directory: app/views/layouts
2 STEP:
Create a file called default.blade.php
3 STEP:
Add your default page layout in HTML to this document.
4 STEP:
Add @yield(‘content1′), @yield(‘content2′) in code for dymanic content.
Example:

</tr>
<tr>
<td style="padding-top: 10px; padding-bottom: 10px">
		  @yield('content1')
      </td><td>
 @yield('content2')

</td>
</tr> 

5 STEP:
Define layout to BaseController for global defining or to your specific controller.
Example:

class BaseController extends Controller {

  public $restful = true;
protecred $layout = 'layouts.default';    

6 STEP:
Now instead of using View::make(‘your_page’) use $this->layout->content=View::make(‘your_page’);
7 STEP:
In your page view ‘your_page.blade.php’ use the following syntax:

@extends('layouts.default')
@section('content1')
Your content for content1
@stop
@section('content2')
Your content for content2
@stop

Thank you for your attention.

Tags: , , , , , ,


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>