I've tried 2 ways that both work but neither feel very clean.
The first is to have some inline javascript that accepts the variable from the view template like:
var x = {{ myServersideVariable }};
(In my case I'm using Jinja2 but same thing would apply to Django templates, Razor in .NET MVC3, Twig in PHP or any number of view templating engines).
Obviously the unclean part about this that there's javascript in the html page rather than in a separate file.
The other option I've used is to have a hidden field populated server side and then consumed on the Javascript end. That feels slightly more clean, but not completely and it's also a bit cumbersome to write.
Is there a better solution or are those pretty much my only options?
P.S.
I'm aware of JSON and in fact I do sometimes have to resort to the first solution if I need to pass something other than primitives. So bonus points for a solution that supports passing JSON objects without having javascript on the page.