It might have to do with the order pages are rendered in. It appears references are parsed by the system before the template is. If I am correct, this might be a tedious job to change. I don't know at what point JavaScript is parsed, but using JavaScript might solve the problem.

Community content is available under CC-BY-SA unless otherwise noted.