remove unnecessary loop in TemplateRepository.getTemplate method