Tiled Gallery: Extract HTML generation logic.

HTML generation logic is separated into templates and partials.