背景: 在做后台功能时候,我们需要把头部和尾部摘出来作为公共模板使用
1:我们使用了Blade模板,并创建一个header.blade.php作为通用的模板。将子页面作为yield输出:
header.blade.php 路径 : /resources/view/admin/common/header.blade.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Laravel 5.5 - @yield(‘title‘)</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="renderer" content="webkit"> <meta http-equiv="Cache-Control" content="no-siteapp" /> <link rel="icon" type="image/png" href="assets/i/favicon.png"> <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png"> <meta name="apple-mobile-web-app-title" content="Amaze UI" /> <script src="{{ URL::asset(‘amaze/assets/js/echarts.min.js‘) }}"></script> <link rel="stylesheet" href="{{ URL::asset(‘amaze/assets/css/amazeui.min.css‘) }}" /> <link rel="stylesheet" href="{{ URL::asset(‘amaze/assets/css/amazeui.datatables.min.css‘) }}" /> <link rel="stylesheet" href="{{ URL::asset(‘amaze/assets/css/app.css‘) }}"> <script src="{{ URL::asset(‘amaze/assets/js/jquery.min.js‘) }}"></script> </head> @yield(‘content‘)
<!--footer-->
<script src="{{ URL::asset(‘amaze/assets/js/amazeui.min.js‘) }}"></script> <script src="{{ URL::asset(‘amaze/assets/js/amazeui.datatables.min.js‘) }}"></script> <script src="{{ URL::asset(‘amaze/assets/js/dataTables.responsive.min.js‘) }}"></script> <script src="{{ URL::asset(‘amaze/assets/js/app.js‘) }}"></script> </body> </html>
2 新建一个index.blade.php 路径: /resources/view/admin/index.blade.php
@extends(‘admin.common.header‘) @section(‘title‘, ‘test‘) @section(‘content‘) <!--此处写你得html代码即可--> @endsection
如果你只是单纯的引入一个文件。也可以这样
@include(‘admin.common.menu‘)
目录结构