Add a magic variable to access the current template. Also don't set the variable if it is not accessed.