如你所见,该文件包含了典型的 HTML 语法。不过,请注意 @Section 和 @yield 命令。顾名思义,@Section 命令定义了视图的一部分内容,而
@yield 指令是用来显示指定部分的内容。
父模板定义right方法,字模板继承right并重写方法
在这里@yield只是占位的作用
<!-- 子模板 child.blade.php-->
@extends('parent')
@section('title','MrChi Blog')
@section('right')<h2><p>this is mrchi's blog,thanks to give me a active!</p></h2>
@endsection
@section('content')<p>hello mrchi:I want to tell you ,this is my country!</p>
@endsection
根据面向对象的知识,子模板的同名方法覆盖父类方法.
同时,子类right 方法中引用的父类方法.
组件&插槽
组件和插槽给内容片段(section)和布局(layout)带来了方便,不过,有些人可能会发现组件和插槽的模型更容易理解。首先,我们假设有一个可复
用的“alert”组件,我们想要在整个应用中都可以复用它:
//alert.blade.php<div class="alert alert-danger"><div class="alert-title">{{$title}}</div>{{$slot}}</div>{{$slot}} 变量包含了我们想要注入组件的内容,现在,要构建这个组件,我们可以使用 Blade 指令 @component:
//使用组件
@component('alert')
@slot('title')
Forbidden
@endslot
You are not allowed to access this resource!
@endcomponent