I Want create a custom module with custom template for override a menu created from the back office administration. I don't want put my custom template in the theme, I want put this file in my custom module (in custommodule/templates/..)
1) I activated twig debug, I can see what is the suggested template menu name : (menu--main.html.twig)
2) I added in my custom .module file the hook theme :
function custommodule_menu_theme($existing, $type, $theme, $path)
{
return array(
'menu__main' => array(
'base hook' => 'menu',
// 'render element' => 'menu', // I tried this, nothing change
// 'template' => 'menu--main', // I tried this, nothing change
),
);
}
3) From my custommodule, I created a directory 'templates'. In this directory, I add the twig file menu--main.html.twig :
<h1> Hello ! <h1>
4) I cleared caches (drush cr)
5) I reloaded the page from my browser. I noticed my custom template isn't called. And if I look in the html structure page, I see :
Why this is the template from the global theme called ? and not my templates/main--menu.html.twig ? I don't understand..
UP
My new code :
function custommodule_theme($existing, $type, $theme, $path) {
$theme=array();
$theme['menu__main'] = array(
'base hook' => 'menu',
'render element' => 'menu',
);
return $theme;
}
But my custommodule/templates/menu--main.html.twig is still not called (I cleared caches). My page always uses the themes/boostrap/templates/menu/menu--main.html.twig in the