【发布时间】:2020-11-20 00:19:57
【问题描述】:
我是 laravel 框架的新手,想使用 laravel 布局母版页,并且习惯在母版页中包含子页面。这是我的页眉和页脚页,app.blade.php 是我的母版页,我使用@yield 显示数据。但这对我不起作用。我的输出显示为空白。
app.blade.php(布局母版页)
<!DOCTYPE html>
<html lang="en">
<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>
@yield('header')
</div>
<div class="content">
@section('content')
<h1> Body </h1>
@endsection
</div>
<div>
@yield('footer')
</div>
</div>
</body>
</html>
Header.blade.php
@extends('app')
<!DOCTYPE html>
<html lang="en">
<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">
<title></title>
<style>
.header
{
height:100px;
width:100%;
background-color: aquamarine;
}
</style>
</head>
<body>
<div class="header">
@section('header')
<center> Layout Header Master page </center>
@show
</div>
</body>
</html>
footer.blade.php
@extends('app')
<!DOCTYPE html>
<html lang="en">
<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">
<title>Document</title>
<style>
.footer
{
height:100px;
width:100%;
background-color: aquamarine;
padding-top: 50px ;
}
</style>
</head>
<body>
<div class="footer">
@section('footer')
<center> Layout Footer Master page </center>
@show
</div>
</body>
</html>
web.php(路由)
Route::get('/masterpage','studentcontroller@viewmasterpage')->name('masterpage');
studentcontroller.php
public function viewmasterpage()
{
return view('layouts/app');
}
【问题讨论】:
-
学生控制器文件在哪里??
-
我再次编辑我的问题,添加学生控制器文件。
标签: php laravel layout laravel-blade master-pages