根据路线删除@include
Remove @include depending on the route
我有一个部分菜单,其中包括一个输入搜索栏。但我不希望搜索栏在所有页面上都可见,只针对两个特定的 uri。有没有办法删除 blade 中包含的内容?
目前看起来是这样的:
<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@include('partials._search')
我在想
<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@if($url)
@include('partials._search')
@endif
使用is()
方法:
@if (request()->is($url))
@include('partials._search')
@endif
或者如果您知道路线名称:
@if (request()->route()->getName() === $routeName)
@include('partials._search')
@endif
要从 blade 模板中检索 URL,请使用 {{ Request::url() }}
。
这将输出类似 http://example.dev/articles
要检索路径,请使用 {{ Request::path() }}
使用上面的示例,这将输出 articles.
我有一个部分菜单,其中包括一个输入搜索栏。但我不希望搜索栏在所有页面上都可见,只针对两个特定的 uri。有没有办法删除 blade 中包含的内容?
目前看起来是这样的:
<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@include('partials._search')
我在想
<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@if($url)
@include('partials._search')
@endif
使用is()
方法:
@if (request()->is($url))
@include('partials._search')
@endif
或者如果您知道路线名称:
@if (request()->route()->getName() === $routeName)
@include('partials._search')
@endif
要从 blade 模板中检索 URL,请使用 {{ Request::url() }}
。
这将输出类似 http://example.dev/articles
要检索路径,请使用 {{ Request::path() }}
使用上面的示例,这将输出 articles.