Template injection function