在Laravel 5中设置Bootstrap导航栏活动类 [英] Setting Bootstrap navbar active class in Laravel 5
问题描述
我一直在想寻找解决方案,但是尤其是在创建助手时并不能真正理解.我是Laravel的新手,我想要一个简单的,甚至不是详细的说明,如何为我的引导导航栏设置活动类.
I've been wondering around looking for solutions, but can't really understand especially when creating helpers. I'm new in Laravel and I want a simple or if not a detailed instruction on how to set the active class for my bootstrap navbar.
这是我到目前为止所做的,但无法完成:
Here's what I've done so far, but can't get it done:
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li class=""><a href="{{ url('/') }}">Home</a>
</li>
<li {{ Request::is('about*') ? ' class="active"' : null }}><a href="{{ url('about') }}">About Us</a>
</li>
<li><a href="{{ url('auth/login') }}">Login</a>
</li>
</ul>
</nav>
<h2 class="">Tobacco Prevention and Control Program</h2>
</div>
编辑
设置class="active"
将激活所有导航丸.预期的效果是,只有当前页面的li
具有active
类.
Setting class="active"
will make all nav-pills active. The intended effect is that only the li
of the current page have the active
class.
编辑
对于那些正在访问此帖子的人.我设法找到了解决方案,但是我不确定它是否整洁.很好,对我来说很好.
For those who are visiting this post. I have managed to get a solution, but I'm not sure if it is neat. Well it's working and fine for me.
<ul class="nav nav-second-level">
<li class="{{ Request::segment(1) === 'programs' ? 'active' : null }}">
<a href="{{ url('programs' )}}" ></i> Programs</a>
</li>
<li class="{{ Request::segment(1) === 'beneficiaries' ? 'active' : null }}">
<a href="{{url('beneficiaries')}}"> Beneficiaries</a>
</li>
<li class="{{ Request::segment(1) === 'indicators' ? 'active' : null }}">
<a href="{{url('indicators')}}"> Indicators</a>
</li>
</ul>
推荐答案
<ul class="nav nav-second-level">
<li class="{{ Request::segment(1) === 'programs' ? 'active' : null }}">
<a href="{{ url('programs' )}}" ></i> Programs</a>
</li>
<li class="{{ Request::segment(1) === 'beneficiaries' ? 'active' : null }}">
<a href="{{url('beneficiaries')}}"> Beneficiaries</a>
</li>
<li class="{{ Request::segment(1) === 'indicators' ? 'active' : null }}">
<a href="{{url('indicators')}}"> Indicators</a>
</li>
</ul>
这篇关于在Laravel 5中设置Bootstrap导航栏活动类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!