Fixed template variable scope