-
Notifications
You must be signed in to change notification settings - Fork 233
Attributes
Shea Lewis edited this page Nov 16, 2015
·
1 revision
Attaching attributes to your menu items is simple. You are able to define as many attributes as you may need to any item through a variety of consistent interfaces - utilize whichever one you think is the cleanest.
Menu::make('Example', function($menu) {
$menu->add('Link One', ['url' => 'link-one', 'class' => 'my-super-class', 'id' => 'link-one']);
$menu->add('Link Two', ['url' => 'link-two', 'class' => 'my-super-class', 'id' => 'link-two']);
});
In this example, both the class
and id
attributes will be attributed to each item.
You may also make use of the attribute()
method to assign attributes rather than passing them through the add()
method. This results is easier to read code:
Menu::make('Example', function($menu) {
$menu->add('Link One', 'link-one')->attribute(['class' => 'my-super-class', 'id' => 'link-one']);
$menu->add('Link Two', 'link-two')->attribute(['class' => 'my-super-class', 'id' => 'link-two']);
});
Menu::make('Example', function($menu) {
$menu->add('Link One', 'link-one')
->attribute('class', 'my-super-class')
->attribute('id', 'link-one');
$menu->add('Link Two', 'link-two')
->attribute('class', 'my-super-class')
->attribute('id', 'link-two');
});
Rendering attributes is simple within your view file. Simply echo out the item's attributes()
method as a raw string, and you'll be good to go! The package will automatically generate the correct HTML syntax.
{!! $item->attributes() !!}
- Active Link Detection
- Append and Prepend
- Attributes
- Dividers
- [Meta Data](Meta Data)
- [Sort By](Sort By)