Tiled Gallery: Extract HTMl generation logic.

HTML generation logic is separated into templates and partials.