It seems as though `templates[0][1]` is necessary, although it's certainly not as clean as I'd like. The location is stored in the tuple at `templates[0]`, unless there's some neater way to access that?

I'm not sure how to combine the two for loops -- they're in separate divs, and have different functionality. I have prevented them from creating the templates divs when it's not necessary, though.