Moved the method that replace homogeneous templates to TemplateHelper for reuse