Fix #7098

Fix #7098 by moving template variable assignment to correct place.