Blade模板引擎子视图
在views文件夹下面新建一个common(名称自定义)文件夹里面存放公共文件footer.blade.php和header.blade.php
引入公共文件:
@include ('common.header')我是文章页面中间内容@include('common.footer')
@include()可以传第二参数,可以通过被引入的页面获取这个参数,比如下面的header.blade.php就能够通过{{$page}}获取到page变量
@include ('common.header',['page'=>'文章页面'])我是文章页面中间内容@include('common.footer')
模板继承:
在views文件夹下面新建一个layouts文件夹里面存放被继承的模板如home.blade.php,并在需要引入的区域写入代码:@yield('content')
Laravel我是公共头部@yield('content')
在需要继承home.blade.php的模板里写入:
@extends('layouts.home') @section('content')我是home.blade.php中@yield('content')区域@endsection
@yield('content')可以改写:
Laravel我是公共头部@section('content')如果用此方法,这里可以添加内容并且能被子模板继承
@show
在需要继承home.blade.php的模板里写入:
@extends('layouts.home') @section('content')我是home.blade.php中@yield('content')区域@endsection
改写后的好处是子视图可以根据自己的需要继承@section('content') @show之间的内容