Skip to content

roboc/Menu-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Menu builder

Easy way to build navigation menus

Scrutinizer Code Quality Build Status

Example usage

Create Menu

$menu = new Menu('main-menu');

Add menu items

$menu->item('Home')->to('/');

Use badges

$menu->item('Inbox')->to('inbox')->badge(5);

Create submenu

$menu->item('Reports')
    ->subMenu( function ( Menu $menu )
    {
        $menu->item('Summary')->to('/reports/summary');
        $menu->item('Detailed')->to('/reports/detailed');
    } );

Render menu

Using JSON renderer

$json = ( new \Roboc\Menu\Renderer\JsonRenderer )->render( $menu );

Output:

[
    {
        "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:

<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

About

Simple menu builder

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages