Php @放错地方

Php @放错地方,php,laravel,laravel-5.4,Php,Laravel,Laravel 5.4,我是拉威尔的新手,我第一次尝试做一个“模块化”页面。一切都很顺利,如果我的基本布局在我的主页上得到扩展,已经设置了一些没有问题的部分/收益(内容、标题等),但是一个特定的@yield一直在错误的位置呈现,我已经将其放在我的head文件(head.blade.php)中,标题已经有了另一个@yield,但这个标题一直在正文中呈现。我试着做了一些测试,发现如果我把我的标题@yield放在里面,它就可以工作了,但是如果我把它放在标签外面,它就会移动到主体上。 这是一种正常的Laravel工作方式(@y

我是拉威尔的新手,我第一次尝试做一个“模块化”页面。一切都很顺利,如果我的基本布局在我的主页上得到扩展,已经设置了一些没有问题的部分/收益(内容、标题等),但是一个特定的
@yield
一直在错误的位置呈现,我已经将其放在我的head文件(head.blade.php)中,标题已经有了另一个
@yield
,但这个标题一直在正文中呈现。我试着做了一些测试,发现如果我把我的标题
@yield
放在
里面,它就可以工作了,但是如果我把它放在标签外面,它就会移动到主体上。 这是一种正常的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>
<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">

@include('includes.head')
@include('includes.nav')
@产量(“工具”)
@产量(‘含量’)
@include('includes.footer')
head.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>
<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">

@收益率('title')====>放在这里正常工作
@yield('title')====>如果这样做,则在主体内部呈现

这是一种正常的浏览器行为。首先,你必须把所有的东西放在正确的地方。这就像你试图不使用叉子吃一些肥肉,然后哭着说你的手在肥肉里:) 您必须始终定义浏览器期望的所有标记。Title标记定义页面的内部标题所在的位置
yield('title')
只是指您在此处插入的名称。它看起来像HTML中的
id

由于您没有向浏览器描述您想在此处插入的内容,因此它试图解决问题,通常是在正文中放置所有不需要的标记的内容(只有在我们谈论的是在标题中省略标记的情况下)。

看起来我是个哑巴。如果@yield包含有效的html标记,它将被放置在右侧place@IsraelPinheiroyield只是一个命令,用于将要命名的文本放在括号中。它可能也包含HTML,因此它将根据您之前输入的字符串放置您的
。但是,仍然需要设置
title
标记