将整个页面划分成不同的模块,
代码部署:
outesweb.php
Route::get('section1',['uses'=>'StudentController@section1']);
appHttpControllersStudentController.php
//模板继承演示 public function section1() { return view('student.section1'); }
esourcesviewslayouts.blade.php
<html> <head> <meta charset="UTF-8"> <title>学习laravel @yield('title')</title> <style> .header{ width:1000px; height: 150px; margin: 0 auto; background: #f5f5f5; border: 1px solid #dddddd; } .main{ width: 1000px; height: 300px; margin: 0 auto; margin-top: 15px; clear: both; } .main .sidebar{ float: left; width: 20%; height: inherit; background: #f5f5f5; border: 1px solid #dddddd; } .main .content{ float: right; width: 75%; height: inherit; background: #f5f5f5; border: 1px solid #dddddd; } .footer{ width:1000px; height: 50px; margin: 0 auto; background: #f5f5f5; border: 1px solid #dddddd; text-align: center; position: absolute; bottom: 6; } </style> </head> <body> <div class="header"> @section('header') 头部 @show </div> <div class="main"> <div class="sidebar"> @section('sidebar') 侧边栏 @show </div> <div class="content"> @yield('content','主要内容区域') </div> <div class="footer"> @section('footer') 底部 @show </div> </div> </body> </html>
esourcesviewsstudentsection1.blade.php
section1
@extends('layouts')
子模板的继承
esourcesviewsstudentsection1.blade.php
section1
@extends('layouts')
@section('header')
@parent
header子模板
@endsection
@section('sidebar')
@parent
sidebar子模板
@stop
@section('title')
我是title
@stop
@section('content')
content
@endsection