add logic for template