A Summary of Overriding template files in Drupal 7

Drupal's theme system allows you to provide alternate template files by way of theme hook suggestions. In other words, you can override the output of nodes, pages, blocks, and more by providing your own template file and using the correct naming scheme. For more information on that naming scheme I suggest reading this article on Drupal 7 Theme Hook Suggestions. Note, that it is also possible to override templates from contributed modules, but whether you can do so depends on the module.

 

The most common method is to create a new suggested template file in a theme. You can find a listing of core templates from drupal.org. All you have to do is create a new template file with a name that targets the template you want to override, place it in your theme, and clear your theme registry (important).

 

However, you can also make template suggestions from a module. Unlike like themes, Drupal doesn't automatically scan modules for new templates, so you have to register your templates from within the module by using hook_theme. For an example, if you wanted to override the template of the node type mynode from the module mymodule, you could place the following in your mymodule.module file:

function mymodule_theme() {
  $themes = array();
   $themes['node__mynode'] = array(
      'variables' => array('node' => NULL),
      'template' => 'node--mynode',
      'path' => drupal_get_path('module', 'mymodule'),   
   );
 
   return $themes;
}

It's important to note, that when your create a new hook_theme or modify one already in your module, you have to clear the theme registry or Drupal won't recongize your changes.