I am trying to get value set in session in a template file, but I don't get the expected value. I tried two methods, but neither of them works for me.
The code in the custom module controller is the following.
$xyz ='tets';
$session = \Drupal::request()->getSession();
//$session->set('xyz', $roles);
$session->set('abc', $xyz);
The code in the template file is the following.
{% set varname = app.session.get('abc') %}
{{ varname }}
I tried using the following code as well.
$tempstore = \Drupal::service('user.private_tempstore')->get('mymodule_name');
$tempstore->set('num_donateur', $num_donateur);