I've just been passing the URL into the templates, instead of computing it in the templates (except for header.html).