Fixes #8815 by correcting wrong variable reference in template