新建layouts.blade.php模板,代碼如下:
模板所在路徑laravel/resources/views/layouts.blade.php
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>輕松學(xué)會(huì)Laravel-@yield('title')</title> <style> .header {width:1000px; height:150px; margin:0 auto; background: #f5f5f5; border:1px solid #ddd; } .main {width: 1000px; height: 300px; margin: 0 auto; margin-top: 15px; clear: both; } .footer {width:1000px; height:150px; margin:0 auto; margin-top: 15px; background: #f5f5f5; border:1px solid #ddd; } .main .sidebar {float:left; width:20%; height:inherit; background: #f5f5f5; border:1px solid #ddd; } .main .content {float:right; width:75%; height:inherit; background: #f5f5f5; border:1px solid #ddd; } </style></head><body><div class="header"> @section('header') 頭部 @show</div><div class="main"> <div class="sidebar"> @section('sidebar') 側(cè)邊欄 @show </div> <div class="content"> @yield('content','主要內(nèi)容區(qū)域') </div></div><div class="footer"> @section('footer') 底部 @show</div></body></html>在StudentController.php控制器中,新建section1方法渲染模板
public function section1(){ return view('student.section1');}新建section1.blade.php模板文件,代碼如下
模板文件所在位置laravel/resources/views/student/section1.blade.php
<!-- 繼承l(wèi)ayouts模板 -->@extends('layouts')<!-- 在區(qū)域塊內(nèi)輸出內(nèi)容 -->@section('header') <!-- 輸出父模板的內(nèi)容 --> @parent header@stop@section('sidebar') sidebar@stop@section('content') content@stop新聞熱點(diǎn)
疑難解答
圖片精選