Suppose i have this hook_theme() in my module, choosing a template inside the module:

 * Implements hook_theme().
 function module_theme($existing, $type, $theme, $path) {
   return array(
     'module-output' => array(
       'template'  => 'output-template',
       'variables' => array(),

If i put the same output-template.tpl.php inside my active theme, Drupal picks up the module's template.

Is there a way to make Drupal understand that if a template with the same filename exists somewhere in the theme, to pick the theme's template and not the module's (like an override)?

  • I thought that was a default feature. Doesn't it happen that way? Commented Oct 16, 2013 at 16:52
  • 1
    yeah thats what i thought too, but Mike below has a point and i discovered the hard way that u have to avoid dashes in your theme definition also..
    – Pan Chrono
    Commented Oct 16, 2013 at 21:17

2 Answers 2


You can override tpl files defined in modules inside your active theme (under the templates directory). But Drupal will look for a file name using the defined theme key name and not the defined template file.

In your case, you should create a module-output.tpl.php file within your theme. Maybe a good practice to name your template file the same as your theme definition.

  • 1
    You are right with your answer. But for all other people coming here, please @pan-chrono 's comment above. Do not use hyphen in your theme definition "-". Use underscores. Take in mind that drupal replace this internally and will expect your tpl to be named using hypens. So for instance if your key is search_results you will need to create a search-results.tpl.php in your theme's templates folder Commented Jul 3, 2015 at 12:22
  • Any doc link to the official Drupal docs on this? Would be great to cite the source of this info here. I looked around but can't find it. Commented Nov 5, 2015 at 16:44

Just to mention here that you can even change the template file name also if you implement template_preprocess_page() for your theme.

So, you can add a new theme suggestion like this:

 * Implements template_preprocess_page().
function YOURTHEMENAME_preprocess_page(&$variables) {
  // Let's assume your tpl file is page--home.tpl.php.
  $variables['theme_hook_suggestions'][] = 'page__home';

Also you can re-order the priority of these theme suggestion as per your needs.

But you should think to write a semantic code as you can.

I usually add new theme suggestion when the client asks to use the front page.tpl for all static page content type like this way:

// Check if this page has defined node object or not.
if(isset($vars['node']) && isset($vars['node']->type) && ($vars['node']->type == 'page')){
  // Make all page nodes wear page--home.tpl.php.
  $vars['theme_hook_suggestions'][] = 'page__home';

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.