I want to use a variable in the Twig file of Drupal 8. And that twig variable should be available for all pages of the site.
Suppose I have a variable $my_variable created in my Form or in Controller. so now I want to use this $my_variable in my twig file.
Like this {{ my_variable }}.
I have already tried this approach :
get $tempstore inside a twig file drupal 8
My Module file:
function my_module_theme() {
return [
'theme_tag' => [
'variables' => ['my_variable' => NULL],
],
];
}
My Controller :
public function callMe() {
$my_variable= "some data here";
return [
'#theme' => 'theme_tag',
'#my_variable' => $my_variable,
];
}
My Twig :
<p> {{ my_variable}} </p>
any help would be appreciated. Thanks!