corrected wrong variable scope in templates