我的原文地址: http://www.jianshu.com/p/0aa1153eac22
模板繼承什麼用? 自然是增強基礎頁面的複用,有利於頁面文檔的條理,也便於更改多處使用的內容,如頁頭、頁尾
1.用法概要
-
@include('common.header') 包含子視圖
-
@extends('article.common.base') 繼承基礎模板
-
@yield('content') 視圖預留位置
-
@section('content') @endsection繼承模板後向視圖預留位置中填入內容
-
{{-- 注釋 --}} Blade模板中注釋的使用
2.具體使用
2.1 建立Article基礎模板base.blade.php
直接使用Bootstrap4模板代碼及CDN,建立視圖基礎模板
路徑resources/views/article/common/base.blade.php
Artilce|標題在此 {{-- 包含頁頭 --}}@include('article.common.header'){{-- 繼承後插入的內容 --}}@yield('content'){{-- 包含頁尾 --}}@include('article.common.footer') 2.2. 建子視圖檔案 頁頭和頁尾
Articles
Articles
2.3 即可繼承模板,實現複用
建立首頁檔案在resources/views/article/index.blade.php
@extends('article.common.base')@section('content') 繼承模板的首頁搞定了!
{{-- 這裡是Blade注釋 --}} @endsection
2.4 如何訪問?
Route::get('/',function(){ return view('article.index');});
3.
X bootstrap4起始模板代碼
Hello, world!