2017 © Pedro Peláez
 

library menu

Html menu generator

image

spatie/menu

Html menu generator

  • Friday, March 2, 2018
  • by Spatie
  • Repository
  • 22 Watchers
  • 339 Stars
  • 84,439 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 42 Forks
  • 4 Open issues
  • 43 Versions
  • 16 % Grown

The README.md

Html Menu Generator

Latest Version on Packagist Tests Total Downloads, (*1)

The spatie/menu package provides a fluent interface to build menus of any size in your php application. If you're building your app with Laravel, the spatie/laravel-menu provides some extra treats., (*2)

If you're looking for a more flexible and renderless solution, maybe our spiritual successor Laravel Navigation is what you're looking for., (*3)

Documentation is available at https://docs.spatie.be/menu., (*4)

Upgrading from version 1? There's a guide for that!, (*5)

Support us

, (*6)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*7)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*8)

Human Readable, Fluent Interface

All classes provide a human readable, fluent interface (no array configuration). Additionally, you can opt for a more verbose and flexible syntax, or for convenience methods that cover most use cases., (*9)

Menu::new()
    ->add(Link::to('/', 'Home'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact'))
    ->add(Html::empty())
    ->render();

// Or just...
Menu::new()
    ->link('/', 'Home')
    ->link('/about', 'About')
    ->link('/contact', 'Contact')
    ->empty()
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/contact">Contact</a></li>
    <li></li>
</ul>

Or a More Programmatic Approach

Menus can also be created through a reduce-like callable., (*10)

$pages = [
    '/' => 'Home',
    '/about' => 'About',
    '/contact' => 'Contact',
];

Menu::build($pages, function ($menu, $label, $url) {
    $menu->add($url, $label);
})->render();
<ul>
    <li><a href="/">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/contact">Contact</a></li>
</ul>

Strong Control Over the Html Output

You can programatically add html classes and attributes to any item in the menu, or to the menu itself., (*11)

Menu::new()
    ->addClass('navigation')
    ->add(Link::to('/', 'Home')->addClass('home-link'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact')->addParentClass('float-right'))
    ->wrap('div.wrapper')
<div class="wrapper">
    <ul class="navigation">
        <li><a href="/" class="home-link">Home</a></li>
        <li><a href="/about">About</a></li>
        <li class="float-right"><a href="/contact">Contact</a></li>
    </ul>
</div

Adding id to elements

You can add id, so you can easily target some of these elements with CSS or JS., (*12)

Menu::new()
    ->id('navigation')
    ->add(Link::to('/', 'Home')->id('home-link'))
    ->add(Link::to('/about', 'About'))
    ->add(Link::to('/contact', 'Contact'))
<ul id="navigation">
    <li><a href="/" id="home-link">Home</a></li>
    <li><a href="/about">About</a></li>
    <li><a href="/contact">Contact</a></li>
</ul>

Not Afraid of Depths

The menu supports submenus, which in turn can be nested infinitely., (*13)

Menu::new()
    ->link('/', 'Home')
    ->submenu('More', Menu::new()
        ->addClass('submenu')
        ->link('/about', 'About')
        ->link('/contact', 'Contact')
    );
<ul>
    <li><a href="/">Home</a></li>
    <li>
        More
        <ul class="submenu">
            <li><a href="/about">About</a></li>
            <li><a href="/contact">Contact</a></li>
        </ul>
    </li>
</ul>

Some Extra Treats for Laravel Apps

The Laravel version of the menu package adds some extras like convenience methods for generating URLs and macros., (*14)

Menu::macro('main', function () {
    return Menu::new()
        ->action('HomeController@index', 'Home')
        ->action('AboutController@index', 'About')
        ->action('ContactController@index', 'Contact')
        ->setActiveFromRequest();
});
<nav class="navigation">
    {{ Menu::main() }}
</nav>

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*15)

Install

You can install the package via composer:, (*16)

``` bash composer require spatie/menu, (*17)


## Usage Documentation is available at https://docs.spatie.be/menu. ## Upgrading to 2.0 Upgrading to 2.0 should be pretty painless for most use cases. ### If you're just building menus... - The `void` and `voidIf` have been removed. These can be replaced by `html` and `htmlIf`, with empty strings as their first arguments - The `prefixLinks` and `prefixUrls` methods have been removed because they were too unpredictable in some case. There currently isn't an alternative for these, besides writing your own logic and applying it with `applyToAll`. ### If you're using custom `Item` implementations... - The `HtmlAttributes` and `ParentAttributes` traits have been renamed to `HasHtmlAttributes` and `HasParentAttributes`. - The `HasUrl` interface and trait has been removed. Url-related methods now also are part of the `Activatable` interface and trait. ### New features... - Added the static `Menu::build` and non-static `Menu::fill` methods to create menu's from arrays. - The `setActive` method on `Activatable` now also accepts a non-strict boolean or callable parameter to set `$active` to true or false. - `Menu::html` and `Menu::htmlIf` now accept a `$parentAttributes` array as their second arguments. ## Changelog Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. ## Testing ``` bash phpunit

Contributing

Please see CONTRIBUTING for details., (*18)

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker., (*19)

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using., (*20)

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium., (*21)

We publish all received postcards on our company website., (*22)

Credits

License

The MIT License (MIT). Please see License File for more information., (*23)

The Versions

02/03 2018

dev-master

9999999-dev https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

02/03 2018

2.5.0

2.5.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

13/11 2017

2.4.1

2.4.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

17/10 2017

2.4.0

2.4.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

29/08 2017

2.3.1

2.3.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

28/08 2017

2.3.0

2.3.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

11/07 2017

2.2.2

2.2.2.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

07/03 2017

2.2.1

2.2.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

07/03 2017

dev-analysis-qgZPnQ

dev-analysis-qgZPnQ https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

09/02 2017

2.2.0

2.2.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

02/02 2017

2.1.3

2.1.3.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

02/02 2017

2.1.2

2.1.2.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

25/01 2017

2.1.1

2.1.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

24/11 2016

2.1.0

2.1.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

11/10 2016

2.0.1

2.0.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

27/09 2016

2.0.0

2.0.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

27/09 2016

2.0.0-beta.4

2.0.0.0-beta4 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

26/09 2016

2.0.0-beta.3

2.0.0.0-beta3 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

26/09 2016

2.0.0-beta.2

2.0.0.0-beta2 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

21/09 2016

2.0.0-beta.1

2.0.0.0-beta1 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

02/09 2016

1.4.0

1.4.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

29/08 2016

1.3.0

1.3.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

01/08 2016

1.2.1

1.2.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

25/06 2016

1.2.0

1.2.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

04/04 2016

1.1.1

1.1.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

30/03 2016

1.1.0

1.1.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

24/03 2016

1.0.0

1.0.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

24/03 2016

0.6.6

0.6.6.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

21/03 2016

0.6.5

0.6.5.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

18/03 2016

0.6.4

0.6.4.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

18/03 2016

0.6.3

0.6.3.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

18/03 2016

0.6.2

0.6.2.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

18/03 2016

0.6.1

0.6.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

18/03 2016

0.6.0

0.6.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

14/03 2016

0.5.3

0.5.3.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

11/03 2016

0.5.2

0.5.2.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

11/03 2016

0.5.1

0.5.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

10/03 2016

0.5.0

0.5.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

09/03 2016

0.4.1

0.4.1.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

09/03 2016

0.4.0

0.4.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

09/03 2016

0.3.0

0.3.0.0 https://github.com/spatie/menu

Html menu generator

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation menu spatie

09/03 2016

0.2.0

0.2.0.0 https://github.com/spatie/navigation

:package_description

  Sources   Download

MIT

The Requires

 

The Development Requires

navigation spatie

25/02 2016

0.1

0.1.0.0 https://github.com/spatie/navigation

:package_description

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

navigation spatie