Remove @include depending on the route

戏子无情 提交于 2019-12-02 13:44:45

问题


I have a menu partial, that includes a input search bar. But i don't want the search bar to be visibel on all pages, only for two specific uri´s. Is there a way to remove that include in blade?

Currently it looks like this:

<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@include('partials._search')

I was thinking something like

<a href="{{ route('all') }}">all</a>
<a href="{{ route('nes') }}">nes</a>
<a href="{{ route('snes') }}">snes</a>
@if($url)
    @include('partials._search')
@endif

回答1:


Use is() method:

@if (request()->is($url))
    @include('partials._search')
@endif

Or if you know route name:

@if (request()->route()->getName() === $routeName)
    @include('partials._search')
@endif



回答2:


To retrieve URL from the blade template, use {{ Request::url() }}. This will output something like http://example.dev/articles

To retrieve path, use {{ Request::path() }} Using the above example, this will output articles.



来源:https://stackoverflow.com/questions/41852449/remove-include-depending-on-the-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!