Auto active <li>

Submitted by Matt - 9 years ago

This macro has the same signature than HTML::linkRoute() but wraps the hypertext link with <li></li>. If the current URL is the specified route, then <li> becomes "active" (<li class="active>...</li>). I use it to quickly build menus. Work well with Bootstrap.

HTML::macro('liLinkRoute', function($name, $title = null, $parameters = array(), $attributes = array()){
    $active = ( URL::current() == URL::route($name, $parameters) ) ? ' class="active"':'';
    return '<li'.$active.'>' . HTML::linkRoute($name, $title, $parameters, $attributes) . '</li>';