Fix variable references within script template