How to make an unordered list from a tree

Last week I showed you how to take an adjacency list in a database and turn it into a nicely indented textual output. Today I will show you how you can take that same (flat) data structure and turn it into an HTML unordered list (UL) using Template Toolkit. The script is available here: If you run the code below it will generate the HTML for the data from last week. $ wget -q -O - | perl - It should look something like this:

The template code code is fairly well commented, so it shouldn't be necessary to explain here what it does.

Now go out and make some nice treeviews on your web pages. And while you're at it, sprinkle some jQuery on top of it to make it interactive.

Update (2020-10-09): Ben Brumm contacted me and suggested linking to an article about storing hierarchical data in SQL. It describes several different methods of storing and querying the tables, with different pros and cons.