Skip to content

Active Link Detection

Shea Lewis edited this page Jun 15, 2015 · 3 revisions

Caffeinated Menus will actually automatically detect the currently active link for you, based on the current URL. Once an item is detected as being the active link, a new active class will be attributed to the item. So you will only need to be sure to echo out the item's attributes from within your view (see the documentation on rendering attributes for more information).

Wildcard Detection

The automatic link detection is only useful for one-on-one URI detection. It does not take into consideration of any dynamic URI segments, such as blog/post/edit/1. For these cases, you may specify that the active state should be activated against other URI segments.

$menu->add('Blog', '#')->active('admin/blog/*');

The above menu item will be active on any URI that matches admin/blog/*:

  • admin/blog
  • admin/blog/create
  • admin/blog/edit/1
  • etc.