I am interested in how other people handle website navigation. Not the styling or usability part, but the generation part. Most websites have some kind of “navigation tree” that is displayed in form of one or more menu levels – in what form do you save and process this tree? The simplest solution is a static menu template, something like this:
<ul id="menu">
<li><a href="…">One</a></li>
<li><a href="…">Two</a></li>
<li><a href="…">Three</a></li>
</ul>
But this is not very flexible. You can’t simply mark the current page in the menu and there’s no simple way of showing or hiding a part of the menu tree depending on the current page. (Or is it?)
I came up with a navigation tree, something like this:
- title: Fruits nodes: - title: Apples - title: Oranges - title: Bananas - title: Music and Stuff url: music nodes: - title: Classical - title: Jazz
This tree gets loaded by a special Navigation
class that can serve parts of the navigation depending on the current request path. This seems to work a bit better, but still I am very curious about other people’s solutions.
MySQL has an article entitled "Managing Hierarchical Data in MySQL" which I have previously found to be quite invaluable. It discusses two common techniques to storing dynamic navigation and their limitations.
If ASP.NET is your flavor, Sitemaps work great
You might find one of my modules useful: CatalystX::Menu::Suckerfish
The menu structure is generated from method attributes. It lacks a way to alter the state of the current page's menu entry, but that shouldn't be difficult to add.
The method attributes are arbitrary strings MenuPath and MenuTitle which specify a slash-delimited path for the menu option in the tree and a string that is used as the menu option label and an html title attribute, where applicable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With