如何在两个部分中使用扩展相同的母版页布局?
How to using extending the same masterpage layout in two partials?
我在 Laravel 上有两个页面。
我可以轻松地在另一个 blade 部分中扩展此布局以获得带有页眉、内容和页脚的工作模式,我可以使用 @extends('master')
.
嵌入它们
我的问题是:
第一页正在使用 header1.blade.php
。
第二页正在使用 header2.blade.php
。
在 master.blade.php
上是我的主页。
<body>
@include('partials.header1')
@yield('content')
@include('partials.footer')
</body>
在 index.blade.php
上使用 master.blade.php
是母版页 extends('master.blade.php
)。
在 listnews.blade.php
上有相同的母版页。
我想在 listnews.blade.php
使用 partials.header2
。
有什么办法吗?
作为@lewis4u 答案的替代方法,您可以使用 @section
指令。
通过这种方式,您可以定义要使用的默认 header,但您可以随时更改它。
首先,将您的 master.blade.php
文件更改为:
<body>
@section('header')
@include('partials.header1')
@show
@yield('content')
@include('partials.footer')
</body>
然后在您的 listnews.blade.php
文件中,在扩展后添加另一个部分:
@section('header')
@include('partials.header2')
@endsection
希望对您有所帮助!
我在 Laravel 上有两个页面。
我可以轻松地在另一个 blade 部分中扩展此布局以获得带有页眉、内容和页脚的工作模式,我可以使用 @extends('master')
.
我的问题是:
第一页正在使用 header1.blade.php
。
第二页正在使用 header2.blade.php
。
在 master.blade.php
上是我的主页。
<body>
@include('partials.header1')
@yield('content')
@include('partials.footer')
</body>
在 index.blade.php
上使用 master.blade.php
是母版页 extends('master.blade.php
)。
在 listnews.blade.php
上有相同的母版页。
我想在 listnews.blade.php
使用 partials.header2
。
有什么办法吗?
作为@lewis4u 答案的替代方法,您可以使用 @section
指令。
通过这种方式,您可以定义要使用的默认 header,但您可以随时更改它。
首先,将您的 master.blade.php
文件更改为:
<body>
@section('header')
@include('partials.header1')
@show
@yield('content')
@include('partials.footer')
</body>
然后在您的 listnews.blade.php
文件中,在扩展后添加另一个部分:
@section('header')
@include('partials.header2')
@endsection
希望对您有所帮助!