Drupal

Sometimes we need to add template suggestions to a module. To do this, we need to alter the registry and add the template suggestion to the preprocess function.

To add a template suggestion for blocks named "mytemplate.tpl.php" in the "theme" subfolder of your module, do the following :

/**
* Implementation of hook_theme_registry_alter().
*/
function MYMODULE_theme_registry_alter(&$theme_registry) {
  $theme_registry['block']['theme paths'][] = drupal_get_path('module', 'MYMODULE') . '/theme';
}
 
/**
* Implementation of hook_preprocess_block().
*/
function MYMODULE_preprocess_block(&$variables) {
  $variables['template_files'][] = 'mytemplate';
}

Syndicate content