1、模板继承
1)定义模板
示例如下
a)主模板(resources/views/common/layout.blade.php):
<html>
<head>
<title>@yield(‘title‘)</title>
</head>
<body>
@section(‘topbar‘)
主页面顶部内容
@show
<div class="container">
@yield(‘content‘)
</div>
</body>
</html>
其中@section(‘xxx‘)...@show和@yield(‘xxx‘)都是用来显示继承模板中指定块的内容的,只是@section(‘xxx‘)...@show之间的内容可以被继承模板通过@parent的方式获取
b)继承模板(resources/views/home/home.blade.php):
@extends(‘common.layout‘)
@section(‘title‘, ‘标题‘)
@section(‘topbar‘)
@parent
<p>子页面顶部内容</p>
@endsection
@section(‘content‘)
<p>子页面主体内容</p>
@endsection
其中@extends指令用来指定子页面所继承的布局,@section(‘xxx‘, ‘内容‘)和@section(‘xxx‘)...@endsection用来定义指定块的内容,@parent用来追加主模板中指定块原有的内容
原文:https://www.cnblogs.com/fengzmh/p/10254262.html