@yield,@section Laravel
@yield, @section in Laravel
大家好,我想在 master.blade.php
中加载 shopReq.blade.php
文件,我成功地做到了这一点。但是当我在 shopReq.blade.php
中加载 modals.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');
});
问题出在相似的名称上。
您不能在 section('content')
中 yield('content')
,您将不得不重命名其中一组。
因此,要么更改 shopReq 中 master 和 section 中的产量,要么更改 shopReq 中模态部分中的产量。
正如milo526用户所说
你有两次@yield('content')
。
对于任何 blade 指令(产量、部分、组件...)
如果括号内有相同的名称,它将被覆盖。
现在我发现您的第二个产量上没有引号“”:
@yield(content)
将 shopReq.blade.php 上的 @yield(content)
替换为 @include('modals')
modals.blade.php
<h1>Hello I am in modals.blade.php</h1>
在路线上
return view('shopReq');
大家好,我想在 master.blade.php
中加载 shopReq.blade.php
文件,我成功地做到了这一点。但是当我在 shopReq.blade.php
中加载 modals.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');
});
问题出在相似的名称上。
您不能在 section('content')
中 yield('content')
,您将不得不重命名其中一组。
因此,要么更改 shopReq 中 master 和 section 中的产量,要么更改 shopReq 中模态部分中的产量。
正如milo526用户所说
你有两次@yield('content')
。
对于任何 blade 指令(产量、部分、组件...)
如果括号内有相同的名称,它将被覆盖。
现在我发现您的第二个产量上没有引号“”:
@yield(content)
将 shopReq.blade.php 上的 @yield(content)
替换为 @include('modals')
modals.blade.php
<h1>Hello I am in modals.blade.php</h1>
在路线上
return view('shopReq');