-
Notifications
You must be signed in to change notification settings - Fork 59
Attributes
niknetniko edited this page Mar 5, 2016
·
4 revisions
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(Builder $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(Builder $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(Builder $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! Caffeinated Menus will automatically generate the correct HTML syntax.
{!! $item->attributes() !!}
{{ item.attributes()|raw }}
🔴 Best Temporary Email - https://1secmail.ru 🔴