Refactor how shared template is generated