The attached module (menutree.py) helps generate sidebar menus. When initializing a MenuTree instance, provide the path of the current page as the 'selected' argument. For example,
sidebarmenu = MenuTree(contentslist=mycontents, selected="/this/page")
I am afraid that the example provided in the module's test routine is not very clear. Each item in the menu list should have its own path where 'ref' is shown. If you run the test routine and examine the output, I am sure you will figure out what to do. It's pretty simple.
An earlier version of this module is used to generate the sidebar menus in my company's web site at www.deltaxresearch.com.