如何在两个部分中使用扩展相同的母版页布局?
Posted
技术标签:
【中文标题】如何在两个部分中使用扩展相同的母版页布局?【英文标题】:How to using extending the same masterpage layout in two partials? 【发布时间】:2017-12-04 03:20:18 【问题描述】:我在 Laravel 上有两个页面。
我可以轻松地在另一个刀片部分中扩展此布局,以获得带有页眉、内容和页脚的工作模式,我可以使用 @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
。
有什么办法吗?
【问题讨论】:
【参考方案1】:作为@lewis4u 的答案的替代方案,您可以使用@section
指令。
这样您可以定义要使用的默认标题,但您可以随时更改它。
首先,将您的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
希望这会有所帮助!
【讨论】:
这是否只是覆盖部分('header')? 我会删除我的答案,因为我觉得你更优雅!以上是关于如何在两个部分中使用扩展相同的母版页布局?的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Sitemappath 控件在网站的母版页中添加面包屑?