Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Freek Van der Herten:
A modern package to generate html menus
Mar 25, 2016 @ 16:17:38

In this new post to his site Freek Van der Herten shares a new package he's worked up to help generate and maintain the status of menus in a Laravel application. While this example is Laravel-centric, there's also a framework-agnostic package that can be used in any application structure too.

Virtually every website displays some sort of menu. Generating html menus might seem simple, but it can become complex very quickly. Not only do you have to render some basic html, but you also have to manage which item is active. If a menu has a submenu you’ll also want the parents of an active item to be active. Sometimes you want to insert some html between menu items.

There are some packages out there that can help generating menus, but most of them have a messy API or have become victims of feature creep. Thanks why we decided to create our own modern menu package that has a beautiful API to work with.

He spends the rest of the post introducing the package, starting with the generation of a basic menu (and something a bit more complex). He also shows the use of the isActive method call to mark something as "active" but the package will handle that automatically for you if you'd like to keep it simple. He ends the post with a listing of the components that make this menu handling work (three of them) and some of the "modern PHP" functionality that they use.

tagged: menu package library html generate output manage active

Link: https://murze.be/2016/03/a-modern-package-to-generate-menus/


Trending Topics: