How to get the correct 'base hook' to override a template file in a custom module? How can I find the 'base hook' to override a template file using a custom module?

'node' and 'user' are pretty straightforward, but others can be a little more elusive.

Example code...

MYMODULE.module:

/**
 ** Implements hook_theme().
 **/
function MYMODULE_theme($existing, $type, $theme, $path) {
  return [
    'username' =&gt; [
      'template' =&gt; 'username',
      'base hook' =&gt; 'how do you get this?',
    ],
  ];
}
Look into the *.module file where the base hook is defined, in this case the User module. The base hook is the key of the template definition:

user.module:

/**
 * Implements hook_theme().
 */

function user_theme() {
  return [
    ... 
    'username' =&gt; [
      'variables' =&gt; ['account' =&gt; NULL, 'attributes' =&gt; [], 'link_options' =&gt; []],
    ],
  ];
}


Then in your *.module file

mymodule.module

/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  return [
    'username__mymodule_template' =&gt; [
      'base hook' =&gt; 'username',
    ],
  ];
}


Start the name of your own hook  with the base hook and double underscores.