rebuild template hierarchy