On Drupal 8, I want pass a variable to a overrides template from my controller OR from the hook theme. I do several tries :
from my .module file :
function ms_story_theme($existing, $type, $theme, $path) {
$theme = array();
$theme['page__ms_story__global'] = array(
'variables' => [
'toto' => "toto", //try one
],
'base hook' => 'page',
'render element' => 'elements',
'#tata' => 'tata', //try two
);
return $theme;
}
from my .php controller file :
class customController extends ControllerBase {
public function map_global($name) {
return [
'#type' => 'markup',
'#theme' => 'page__ms_story__global',
'#markup' => $this->t("Implement method: hello with parameter(s): $name"),
'#tutu' => "tutu", //try three
'variables' => [
"tyty" => "tyty", //try four
],
];
}
}
But when I want display all available variable from my overrided template file (via {{ kint() }} ), I don't see anywhere variables I want add. Variables 'toto' 'tata' tutu' and 'tyty' aren't present in the array structure displayed via kint (I cleared all cache of course)
Where is my mystake ?
Bonus question : how can I add a variable who use not any cache ? (the variable is calculated again every time the user load page ?