bumbummen99/bs4menu

This package is abandoned and no longer maintained. No replacement package was suggested.

Dynamic menu builder for Bootstrap 4.

1.1 2018-02-28 12:07 UTC

This package is auto-updated.

Last update: 2020-08-29 07:27:01 UTC


README

Simple dynamic menu building system.

PHP framework agnostic. The default renderer uses Bootstrap 3 class names and markup.

Installation

composer require anlutro/menu - pick the latest tag visible in the github tag list or on packagist.

Laravel 4

Add bs4menu\ServiceProvider to the list of providers in app/config/app.php. Optionally, add an alias for 'Menu' => 'bs4menu\Facade' as well. The menu builder instance can be accessed via the facade or via automatic dependency injection by type hinting.

Do artisan config:publish anlutro/menu to change the default Bootstrap 3-specific settings.

Usage

Set up a shared instance of Menu\Builder. Create the menus you need.

$builder = new bs4menu\Builder;
$menu = $builder->createMenu('left');

If you're using Laravel 4, you can use Menu:: instead of $builder-> provided you set up an alias as shown in the installation instructions above.

From here, you can add items to your menus from anywhere.

$menu->addItem('Item 1', '/my-uri');

// you can add custom html attributes to your items
$menu->addItem('Item 2', '/my-uri', ['class' => 'custom-class']);

// use priorities to push items to the top or bottom of your menu
// items have priority 0 by default.
$menu->addItem('First item', '/my-uri', [], -50);
$menu->addItem('Last item', '/my-uri', [], 50);

Adding submenus works similarly.

$submenu = $menu->addSubmenu('Sub Menu');
$submenu->addItem('Sub item 1', '/my-uri');

When you want to render a menu, call render($menu) and echo it.

echo $builder->render('left');

By default, Bootstrap 3-specific classes are used. If you want to use something else, you need to create your own class implementation of bs4menu\Renderers\RendererInterface and either do $builder->setDefaultRenderer('MyRenderer') or $builder->render('name_of_menu', $myRenderer).

Contact

Open an issue on GitHub if you have any problems or suggestions.

License

The contents of this repository is released under the MIT license.