Easy way to build navigation menus, (*1)
, (*2)
Example usage
$menu = new Menu('main-menu');
$menu->item('Home')->to('/');
Use badges
$menu->item('Inbox')->to('inbox')->badge(5);
$menu->item('Reports')
->subMenu( function ( Menu $menu )
{
$menu->item('Summary')->to('/reports/summary');
$menu->item('Detailed')->to('/reports/detailed');
} );
Using JSON renderer
$json = ( new \Roboc\Menu\Renderer\JsonRenderer )->render( $menu );
Output:, (*3)
[
{
"title": "Home",
"link": "\/"
},
{
"title": "Inbox",
"link": "inbox",
"badge": {
"value": 5,
"attributes": []
}
},
{
"title": "Reports",
"children": [
{
"title": "Summary",
"link": "\/reports\/summary"
},
{
"title": "Detailed",
"link": "\/reports\/detailed"
}
]
}
]
Using simple HTML renderer
$html = ( new \Roboc\Menu\Renderer\HtmlRenderer )->render( $menu );
Output:, (*4)
<ul id="main-menu">
<li><a href="/">Home</a></li>
<li><a href="/inbox">Inbox <span class="badge">5</span></a></li>
<li>Reports
<ul>
<li><a href="/reports/summary">Summary</a></li>
<li><a href="/reports/detailed">Detailed</a></li>
</ul>
</li>
</ul>
Other
You can create your own menu renderer or build menu output direclty in your code, (*5)