3 回答

TA貢獻1876條經驗 獲得超7個贊
問題: 您的刀片存在一些問題。
每個開始
@section
標簽都需要一個結束@endsection
標簽。標簽部分應該包含您想要在其間顯示的所有內容。
您不需要添加整個內容,
<html> etc.
只需添加必要的代碼即可我認為內容應該是收益,因為您可能想在那里插入其他頁面的內容。
我還認為您很困惑@include
,@yield
如果您想外包頁眉和頁腳,您可以簡單地 @include('yourFolder/footer') 并插入代碼
解決方案:
更改
@yield
為@include
更改
@section
為@yield('content')
例子:
文件名為:header.blade.php
<div class="header">
<center> Layout Header Master page </center>
</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<title>Master Page</title>
</head>
<body>
<div>
@include('header')
<div class="content">
@yield('content')
</div>
@include('footer')
</div>
</body>
</html>
之后您可以創建一個新視圖:example.blade.php
@extends('layout.app')
@section('content')
//put your content here
@endsection

TA貢獻1794條經驗 獲得超8個贊
header.blade.php(只需使用代碼刪除其他)
@section('header')
<center> Layout Header Master page </center>
@endsection
footer.blade.php(只需使用代碼刪除其他)
@section('footer')
<center> Layout Footer Master page </center>
@endsection
應用程序.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<title>Master Page</title>
</head>
<body>
<div>
<div class="header">
@include('header')
</div>
<div class="content">
@yield('content')
</div>
<div class="footer">
@include('footer')
</div>
</div>
</body>
</html>
學生控制器.php
public function viewmasterpage()
{
return view('layouts.app');
}

TA貢獻1828條經驗 獲得超3個贊
您誤解了 @extends、@yield 和 @section 指令。
@extends 使用另一個刀片文件,并用它定義的 @sections 填充 @yield 指令。
說你有app.blade.php
<html>
<body>
@yield('header')
@yield('content')
@yield('footer')
</body>
</html>
那么你可以說landing.blade.php
@extends('app')
@section('header')
<header>I am the header for the landing page!</header>
@endsection
@section('content')
<div>I am the content for the landing page!</div>
@endsection
@section('footer')
<header>I am the footer for the landing page!</footer>
@endsection
- 3 回答
- 0 關注
- 169 瀏覽
添加回答
舉報