Laravel5 模板引擎标签介绍

@extends()

继承父类模板页

@section()

在父类模板页中,使用@section用于标记区块,而在子模板页中,使用@section则是重写对应的区块

父类页(base.blade.php)

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>base-@yield('title')</title>
    <style type="text/css">
        .footer {
            width:1000px;
            height:150px;
            margin:0 auto;
            margin-top: 15px;
            background: #f5f5f5;
            border:1px solid #ddd;
        }
        .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;
        }
        .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')
            侧边栏
            @show
        </div>
        <div class="content">
            @yield('content','主要内容区域')
        </div>
    </div>
    <div class="footer">
        @section('footer')
        底部
        @show
    </div>
</body>
</html>

子类页(section.blade.php)

@extends('base')

@section('title')
    section
@stop

@section('header')
    @parent
    重写
@stop

@yield

在父类模板页中,使用@yield用于标记区块,与section()的区别:@yield()不能保留父类模板页对应区块的内容,但@section()可以。

@parent

在子模板页中,在@section重写部分使用@parent可以保留父类模板对应区块的内容

@section('header')
    @parent
    重写部分
@stop

@stop

结束重写,进行内容解析。

@show

执行到此处时将该 section 中的内容输出到页面。

@append

追加内容。

@section('content')
加一行内容
@append
 
@section('content')
再加一行内容
@append
 
@section('content')
加够了,到此为止吧。
@stop

@override

把以上的所有定义覆盖掉。

@section('content')
加一行内容
@append

@section('content')
再加一行内容
@append

@section('content')
加够了,结束吧
@stop

@section('content')
都不要了,我说的。
@override

猜你喜欢

转载自www.cnblogs.com/toney-yang/p/9189822.html
今日推荐