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>
EDIT
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.
Advertisement
Answer
<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>