Getting the base url of the website and globally passing it to twig in Symfony 2
This is now available for free in twig templates (tested on sf2 version 2.0.14)
{{ app.request.getBaseURL() }}
In later Symfony versions (tested on 2.5), try :
{{ app.request.getSchemeAndHttpHost() }}
Why do you need to get this root url ? Can't you generate directly absolute URL's ?
{{ url('_demo_hello', { 'name': 'Thomas' }) }}
This Twig code will generate the full http:// url to the _demo_hello route.
In fact, getting the base url of the website is only getting the full url of the homepage route :
{{ url('homepage') }}
(homepage, or whatever you call it in your routing file).