A new menu-system

I know that I haven’t been updating this page so often lately, but I’ve been busy with other things. One of those things is my new menu-system.

The main requirement for the new system was, that it should be able to deal with a tree of pages several levels deep. The new system handles this beautifully, as you can see at the sitemap. Notice how the lists are nested within each other. The most extreme case is at the bottom, where I use five levels to describe the structure of my Danish Stuff.

To define this structure, I have all the pages specify their parent and their children. All pages have a parent, but does not necessarily have any children. I store all this information in a huge array, which means that it is extremely easy to access the information.

Because all the pages have a reference directly to their parent, it’s quite easy to find your way back to the root of the tree. All you have to do, is to use a recursive function. This function takes one argument: the node who’s parent we want to find. So the function just adds the node to a global array, and then it calls itself with the parent as an argument. This means that you’ll eventually reach the root, where the parent will be an empty string (''). It’s called recursion because we have a function that keeps executing itself until some condition has been met. Because I can now use recursion, the code needed to build the sitemap, has been cut in half.

The next task, is to make some tools to make it easier for me (and eventually also others) to maintain the structure. I’ll let you know when it’s ready.

Leave a comment