Note: I didn't write this method, I just extracted it from TemplateContentOutlinePage so that I could use it as well.