Laravel - blade 模板繼承的使用


1. 模板文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@yield('title')</title>
    <style>
        .header{
            width:100%;
            min-height:100px;
            background:gold;
        }
        .main{
            width:100%;
            min-height:400px;   
        }
        .main .sidebar{
            width:30%;
            height:400px;
            float:left;
            background:yellow;
        }
        .main .content{
            width:70%;
            height:400px;
            float:left;
            background:green;
        }
        .footer{
            clear:both;
            width:100%;
            min-height:100px;
            background:blue;
        }
    </style>
</head>
<body>
    <div class="header">
        @section('header')
        頭部. 
         section可以定義視圖變量,也可以在內部進行拓展.(命令定義一個內容區塊)
         yield 只是聲明定義,不可拓展. ( “顯示指定區塊” 的內容。)
        @show
    </div>

    <div class="main">
        <div class="sidebar">
            @section('sidebar')
            側邊欄
            @show
        </div>
        <div class="content">
           @yield('content','主要內容區域')
        </div>
    </div>

    <div class="footer">
        @section('footer')
        底部
        @show
    </div>
</body>
</html>
 

2. 要繼承的文件

@extends('layout')

<!-- 重寫頭部 -->
@section('header')
    <!-- 繼承之前的 -->
    @parent
    <h1>重寫頭部</h1>
@stop

<!-- 使用 yield.  先定義section  -->
@section('content')
  content12
@stop

@section('title')
  一拳超人
@stop


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM