【发布时间】:2023-03-20 20:16:02
【问题描述】:
我是 Laravel 的新手,我第一次尝试做一个“模块化”页面。一切都很好,我的基本布局在我的主页上得到了扩展,已经设置了一些没有问题的部分/产量(内容、标题等),但是一个特定的 @yield 一直在错误的地方呈现,我'已经把它放在我的头文件 (head.blade.php) 中,它已经有另一个 @yield 的标题,但那个不断在正文中呈现。我尝试做一些测试,发现如果我把我的标题@yield 放在<title></title> 里面,它工作正常,但是如果我把它放在标签之外,它就会移动到正文中。
这是一种正常的 Laravel 工作方式(@yield 不能单独存在,只能在标签内)或者有什么问题?
default.blade.php
<!doctype html>
<html>
<head>
@include('includes.head')
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--no-desktop-drawer-button">
@include('includes.nav')
@yield('tools')
<main class="mdl-layout__content">
<div class="page-content">
@yield('content')
</div>
</main>
@include('includes.footer')
</div>
</body>
</html>
head.blade.php
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="cache-control" content="no-cache">
<meta name="description" content="XXXXXX">
<meta name="author" content="XXXXXXXXXXXXX">
<title>@yield('title')</title> =====> Works normally if put here
@yield('title') =====> Rendered inside the body if put that way
<!-- jQuery 3.2.1 -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- Normalize CSS -->
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<!-- Dialog Polyfill -->
<link rel="stylesheet" type="text/css" href="css/dialog-polyfill.css">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
【问题讨论】:
标签: php laravel laravel-5.4