Active state macro

Submitted by xtrasmal - 10 years ago

Check if the request matches the url. If so, add an active class to the menu item.

<?php
/* 
 * Add this to app/start/global.php
*/

HTML::macro('activeState', function($url)
{
    
    return Request::is($url) ? 'active' : '';

});

/* 
 * Example usage:
*/
?>
    <ul>
		<li class="{{HTML::activeState('blog')}}">
            <a href="{{ URL::route('blog')}}">Blog</a>
        </li>
		<li class="{{HTML::activeState('about')}}">
            <a href="{{ URL::route('about')}}">About</a>
        </li>
		<li class="{{HTML::activeState('contact')}}">
            <a href="{{ URL::route('contact')}}">Contact</a>
        </li>
	</ul>