Download the PHP package tobento/service-menu without Composer
On this page you can find all versions of the php package tobento/service-menu. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tobento/service-menu
More information about tobento/service-menu
Files in tobento/service-menu
Package service-menu
Short Description A simple and fluent menu builder.
License MIT
Homepage https://www.tobento.ch
Informations about the package service-menu
Menu Service
With the Menu Service you can build menus easily.
Table of Contents
- Getting started
- Requirements
- Highlights
- Simple Example
- Documentation
- Menu
- Creating menu items
- Creating subitems
- Additional menu items
- Icons
- Badges
- Sorting items
- Iterating items
- On specific item
- On parent items
- Active item
- Get item(s)
- Tags
- Escaping
- Menus
- Examples
- Menu
- Credits
Getting started
Add the latest version of the Menu service project running this command.
Requirements
- PHP 8.0 or greater
Highlights
- Framework-agnostic, will work with any project
- Decoupled design
Simple Example
Here is a simple example of how to use the Menu service.
Render the menu:
Both menus from above will produce the following output.
Documentation
Menu
Creating menu items
Creating items with the add() method.
Creating items with the build in methods.
Creating items with the many() method.
Creating subitems
Creating subitems is done by defining the parent item by its id.
Additional menu items
Link To First Child
The menu item, links to the first child menu link if exists, otherwise it will not be rendered at all.
Icons
Creating Icons
By default, icons will not be created at all.
A simple example how to create icons:
Creating Icons With The Icon Service
You may use the menu icon factory to create icons using the Icon Service.
Render Only Icons
Use the method if you want to render the icons only:
Badges
Badges can be used to add additional information to a menu item:
Will output:
Badge If
You may use the method which renders badges only if the given parameter value validates to .
Sorting items
Iterating items
By using the filter method:
By using the each method having access to data tree and tags:
On specific item
On parent items
Active item
Render only active tree items:
Set the items active on the item itself:
Get item(s)
Note: Items tree data and tags are not available yet, except item tag.
Get single item:
Get all items:
Tags
With tags you can manage the menu tags being rendered.
Menu Tags
Item Tags
Escaping
Html escaping is done for you on rendering the menu. Except on the Tag class you will need to do it by yourself:
Menus
Examples
Add active class to active item only
Add active class to active items
Credits
- Tobias Strub
- All Contributors