Layvel的@yield,@ section

时间:2017-08-20 09:58:08

标签: php laravel laravel-5 laravel-blade

大家好我想在shopReq.blade.php中加载master.blade.php文件并且我成功完成了这项工作。但是当我在modals.blade.php中加载shopReq.blade.php文件时,它不包括在内。我在这里做错了吗?请帮忙。

master.blade.php(在views / layouts中):

<html>
   <body >
          @yield('content')
    </body>
</html>

shopReq.blade.php(在视图中)

@extends('layouts.master')
@section('content')
<h1>Hello I am in shopReq.blade.php
@yield(content)
@endsection

modals.blade.php(在视图中)

@extends('shopReq')
@section('content')
<h1>Hello I am in modals.blade.php
@endsection

web.php:

Route::group(['middleware' =>['web']], function()
    {
    Route::get('/', function () {
        return view('welcome');
    })->name('home');
});

3 个答案:

答案 0 :(得分:3)

使用@yield(content)

替换shopReq.blade.php上的@include('modals')

modals.blade.php

<h1>Hello I am in modals.blade.php</h1>
路线上的

return view('shopReq');

答案 1 :(得分:2)

正如用户milo526所说。

你有@yield('content')两次。

对于任何刀片指令(yield,section,component ...)

如果括号内有相同的名称,则会被覆盖。

现在我发现你没有报价&#39; &#39;在你的第二次收益:

@yield(content)

答案 2 :(得分:1)

问题在于名称相似。 你不能在yield('content')section('content')来重命名其中一组。

因此,要么更改shopReq中的master和section中的yield,要么更改shopReq中的yield,以及modal中的部分。

相关问题