laravel之blade模板标签的含义
父布局-layout.blade.php
<div class="header">
@section('header')
header
@show
</div>
<div class="main">
<div class="sidebar">
@section('sidebar')
sidebar
@show
</div>
<div class="content">
@yield('content','主要内容区域')
content
</div>
</div>
<div class="footer">
@section('footer')
footer
@show</div>
</body>
</html>
子布局-son.blade.php
@extends('layouts')
@section('header')
@parent
heihei
@stop
@section('sidebar')
边栏
@stop
1.@section(‘name’): 块,可@parent继承使用父layout中定义的内容
2.@yield(‘name’): 字段,@parent无效,要么内容是子layout的内容,要么是父layout的内容,当子layout未定义时,显示父layout的内容
3.@extends(‘layouts’),继承模板
4.@parent,继承父模板的内容
@show与@stop,@overwrite,@append的使用
@show:将内容输出到界面,在子模板中可以继承使用
@stop:在模板中不继承可以使用
列子:
//parent
@section('main')
main
@show
@section('footer')
footer
@stop
//son
@extends('parent')
@section('main')
son-main
@stop
@section('footer')
son-footer
@stop
只会显示son-main,son-footer不会显示
@append: 还可以用同一@section(‘name’),添加数据
@section('main') hehe @append @section('main') xixi @append
输出hehe xixi
@overwrite: 还可以用同一@section(‘name’),添加数据
@section('main') hehe @append @section('main') xixi @overwrite
输出xixi