Fix incorrect logic in template