How to access session variables in Twig template?
You can inject new variables into templates by using the appropriate preprocess hook in your theme:

function mytheme_preprocess_page(&amp;$variables) {
  // code to get value...
  $variables['myvariable'] = $value;
}


Then in the corresponding template:

{{ myvariable }}

You might have caching issues with this though.