laravel5.1框架基礎(chǔ)之Blade模板繼承簡(jiǎn)單使用方法分析
本文實(shí)例講述了laravel5.1框架基礎(chǔ)之Blade模板繼承簡(jiǎn)單使用方法。分享給大家供大家參考,具體如下:
模板繼承什么用? 自然是增強(qiáng)基礎(chǔ)頁(yè)面的復(fù)用,有利于頁(yè)面文檔的條理,也便于更改多處使用的內(nèi)容,如頁(yè)頭、頁(yè)腳
1.用法概要
@include('common.header')包含子視圖@extends('article.common.base')繼承基礎(chǔ)模板@yield('content')視圖占位符@section('content')@endsection繼承模板后向視圖占位符中填入內(nèi)容{{-- 注釋 --}}Blade模板中注釋的使用
2.具體使用
2.1 新建Article基礎(chǔ)模板base.blade.php
直接使用Bootstrap4模板代碼及CDN,新建視圖基礎(chǔ)模板
路徑resources/views/article/common/base.blade.php
<!DOCTYPE html><html lang="en">
<head>
<title>Artilce|標(biāo)題在此</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge"> <link rel="stylesheet" rel="external nofollow" rel="external nofollow" >
</head>
<body>
{{-- 包含頁(yè)頭 --}}
@include('article.common.header')
{{-- 繼承后插入的內(nèi)容 --}}
@yield('content')
{{-- 包含頁(yè)腳 --}}
@include('article.common.footer')
<script src="http://ajax.useso.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/js/bootstrap.js"></script>
</body>
</html>
2.2. 建子視圖文件 頁(yè)頭和頁(yè)腳
頁(yè)頭文件 resources/views/article/common/header.blade.php
<nav class="navbar navbar-light bg-faded">
<div class="container">
<a class="navbar-brand" href="#" rel="external nofollow" rel="external nofollow" >Articles</a>
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/article" rel="external nofollow" >首頁(yè) <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#" rel="external nofollow" rel="external nofollow" >寫(xiě)文章</a>
</li>
</ul>
<ul class="nav navbar-nav pull-right">
<li class="nav-item">
<a href="" class=" rel="external nofollow" rel="external nofollow" btn btn-primary-outline">登錄</a>
</li>
<li class="nav-item">
<a href="" class=" rel="external nofollow" rel="external nofollow" btn btn-success-outline">注冊(cè)</a>
</li>
</ul>
</div>
</nav>
頁(yè)腳文件 resources/views/article/common/footer.blade.php
<div class="footer"
style="width: 100%;height: 300px;background-color: #00B388;padding-top: 50px;">
<div class="container">
<h1 style="color: #FFFFFF;font-size: 1.5em;">Articles</h1>
</div>
</div>
2.3 即可繼承模板,實(shí)現(xiàn)復(fù)用
新建主頁(yè)文件在resources/views/article/index.blade.php
@extends('article.common.base')
@section('content')
<div class="container" style="height: 500px;text-align: center;">
<h1 style="position: absolute;left: 35%;top: 30%;">繼承模板的主頁(yè)搞定了!</h1>
{{-- 這里是Blade注釋 --}}
</div>
@endsection
2.4 如何訪問(wèn)?
需要路由以及控制器配合,這里簡(jiǎn)單只用路由實(shí)現(xiàn),詳細(xì)內(nèi)容請(qǐng)點(diǎn)擊,以及接下來(lái)的其它文段
在app/Http/routes.php 路由注冊(cè)文件寫(xiě)上如下代碼
Route::get('/',function(){
return view('article.index');
});
啟動(dòng)你的配置的laravel跑的服務(wù)器,比如我在目錄地址下php artisan serve
瀏覽器輸入 : localhost:8000,即可看到效果圖
3. 效果圖

articles效果圖|色彩 #00B388
X bootstrap4起始模板代碼
bootstrap4文檔
<!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags always come first --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="x-ua-compatible" content="ie=edge"> <!-- Bootstrap CSS --> <link rel="stylesheet" rel="external nofollow" rel="external nofollow" > </head> <body> <h1>Hello, world!</h1> <!-- jQuery first, then Bootstrap JS. --> <script src="http://ajax.useso.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> <script src="https://cdn.rawgit.com/twbs/bootstrap/v4-dev/dist/js/bootstrap.js"></script> </body> </html>
更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門(mén)與進(jìn)階教程》、《php優(yōu)秀開(kāi)發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家基于Laravel框架的PHP程序設(shè)計(jì)有所幫助。
- 分享5個(gè)非常有用的Laravel Blade指令
- Laravel 5框架學(xué)習(xí)之Blade 簡(jiǎn)介
- laravel 5 實(shí)現(xiàn)模板主題功能(續(xù))
- laravel 5 實(shí)現(xiàn)模板主題功能
- Laravel框架基礎(chǔ)語(yǔ)法與知識(shí)點(diǎn)整理【模板變量、輸出、include引入子視圖等】
- Laravel框架Blade模板簡(jiǎn)介及模板繼承用法分析
- Laravel實(shí)現(xiàn)通過(guò)blade模板引擎渲染視圖
- PHP的Laravel框架中使用AdminLTE模板來(lái)編寫(xiě)網(wǎng)站后臺(tái)界面
- Laravel框架中Blade模板的用法示例
- Laravel中的Blade模板引擎示例詳解
- Laravel框架之blade模板新手入門(mén)教程及小技巧
- Laravel 5.1 框架Blade模板引擎用法實(shí)例分析
相關(guān)文章
ThinkPHP連接數(shù)據(jù)庫(kù)操作示例【基于DSN方式和數(shù)組傳參的方式】
這篇文章主要介紹了ThinkPHP連接數(shù)據(jù)庫(kù)操作,結(jié)合實(shí)例形式分析了thinkPHP基于DSN方式和數(shù)組傳參的方式進(jìn)行數(shù)據(jù)庫(kù)連接的實(shí)現(xiàn)步驟與屬性設(shè)置、控制器、模板使用等相關(guān)操作技巧,需要的朋友可以參考下2018-03-03
Zend Framework框架的registry(注冊(cè)表)使用示例
這篇文章主要介紹了Zend Framework框架的registry(注冊(cè)表)使用示例,提供對(duì)象方式使用與set、get方法使用示例,需要的朋友可以參考下2014-03-03
PHP Curl模擬登錄微信公眾平臺(tái)、新浪微博實(shí)例代碼
這篇文章主要介紹了PHP Curl模擬登錄微信公眾平臺(tái)、新浪微博實(shí)例代碼的相關(guān)資料,涉及到php curl模擬登錄相關(guān)知識(shí),需要的朋友可以參考下2016-01-01
laravel中短信發(fā)送驗(yàn)證碼的實(shí)現(xiàn)方法
在做用戶注冊(cè)和個(gè)人中心的安全管理時(shí)常常需要用到短信發(fā)送驗(yàn)證碼,下面這篇文章主要給大家介紹了關(guān)于laravel中短信發(fā)送驗(yàn)證碼的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04
PHP對(duì)稱加密算法(DES/AES)類(lèi)的實(shí)現(xiàn)代碼
本篇文章主要介紹了PHP對(duì)稱加密算法(DES/AES)類(lèi)的實(shí)現(xiàn)代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11

