I'd like to pass a variable to an overridden Twig template that is located in my custom module (not in a theme).
Following this answer and this answer, I wrote this code in mymodule.module:
function mymodule_preprocess_page(array &$variables) {
$variables['hello'] = 'world';
}
function mymodule_theme_suggestions_node_add_list(array $variables) {
$suggestions = [];
$suggestions[] = 'node_add_list__' . 'custom';
return $suggestions;
}
function mymodule_theme() {
return [
'node_add_list__custom' => [
'base hook' => 'node_add_list',
],
];
}
Then, I have added in mymodule/templates/node-add-list--custom.html.twig:
myvar: {{ hello }}
However nothing appears after "myvar: " when I refresh the page. I mention that I cleared the cache.
Is there something specific to manage when we use hook_preprocess_page()
with hook_theme_suggestions_HOOK()
/hook_theme()
?