Convert templates to fragments to deduplicate code