如何解决Laravel Blade 内部的产量
我有一个用于用户面板视图的母版页 (master_2),在那里我已经有一个用于主页面内容(等页眉页脚)的母版页 (master_1),无论如何我有这个用于 dynamic,master_1 :
@extends('master_1')
@section('website_title','user panel - ' . @yeild('panel-title'))
在子视图中:
@extends('master_2')
@section('panel-title','dashboard')
The "yield" expression can only be used inside a function
如果您能提供更好的解决方案,我将不胜感激。
解决方法
基本上 @yield
用作子内容的占位符/插槽。
例如,这可以是 master-1.blade.php
<!DOCTYPE html>
<html >
<!-- BEGIN: Head -->
<head>
<meta charset="utf-8">
@yield('head')
<link rel="stylesheet" href="link/to/base-styles.css" />
<script src="link/to/base-script.js"></script>
@yield('pre-scripts')
@yield('styles')
</head>
<body>
@yield('header')
@yield('main')
@yield('footer')
@yield('post-scripts')
</body>
</html>
对于master-2.blade.php
:
@extends('master-1')
@section('pre-scripts')
Scripts here will load before the body
@endsection
@section('header')
Add header markup here
@endsection
@section('main')
You can add main body markup
You can also yield more (sub) content
@yield('sub-content')
And if you @extend('master-2'),you can can slot html into those @yield-ed sections.
@endsection
@section('footer')
Add footer markup here
@endsection
@section('post-scripts')
Scripts here will load at the end of the page body
@endsection
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。