Before this fix the renderer was not able to save the templates and types in the correct way. It still needs some cleanup, but it works now.
This part handles the building of the template tree, which then gets used later by the containers.