How to access session variables in Twig template?

14/07/2018


In a custom module I specified in the hook_preprocess_page function the following session variable:

if (isset($blockNameState) && $blockNameState == 'open') {
   $tempstore->set($blockNameState, 'close');
}
else {
   $tempstore->set($blockNameState, 'open');
}

Let’s assume the above code ran with $blockNameState = ‘block1_state’ and there is key/value pair ‘block1_state/open’ in the $tempstore.

How do I access the key/value pair in a Twig template?

Can’t run the following PHP command in Twig:

$blockNameState = $tempstore->get($blockNameState);

قالب وردپرس