如何隐藏主页(index.blade.php)上的侧边栏? 目前,在master.blade.php中我有类似的内容:
<main class="py-5">
<div class="row" style="margin-right:15px;">
<div class="col-md-9 col-sm-12 col-xs-12">
@yield('content')
</div>
<div class="col-md-3 col-sm-12 col-sx-12">
@include('sidebar')
</div>
</div>
</main>
我需要在除主页(index.blade.php)之外的所有子页面上显示侧栏。
谢谢
答案 0 :(得分:1)
假设索引页面是根/
,您可以像这样检查:
@unless(request()->is('/'))
<div class="col-md-3 col-sm-12 col-sx-12">
@include('sidebar')
</div>
@endunless
----编辑
@if(request()->is('/'))
<div class="col-md-12 col-sm-12 col-xs-12">
@yield('content')
</div>
@else
<div class="col-md-9 col-sm-12 col-xs-12">
@yield('content')
</div>
<div class="col-md-3 col-sm-12 col-sx-12">
@include('sidebar')
</div>
@endif
答案 1 :(得分:0)
您可以将参数从index.blade.php文件传递到布局,例如:@extends('layouts.master', ['noSideBar' => true])
。然后在您的master.blade.php中:
@unless(isset($noSideBar))
<div class="col-md-3 col-sm-12 col-sx-12">
@include('sidebar')
</div>
@endunless
如果您还希望其他块具有不同的类,则代码将如下所示:
<main class="py-5">
<div class="row" style="margin-right:15px;">
<div class="{{ isset($noSideBar) ? 'col-md-12 : 'col-md-9' }} col-sm-12 col-xs-12">
@yield('content')
</div>
@unless(isset($noSideBar))
<div class="col-md-3 col-sm-12 col-sx-12">
@include('sidebar')
</div>
@endunless
</div>
</main>