Deduplicate template code