简体   繁体   中英

Drupal 6 - Custom Node Type Template in Module

I have a module which adds a new content type.

For this content type I want to supply a node_contenttype.tpl.php node type template, but Drupal will not recognize this template in the module directory, only in a theme.

How do I get Drupal (6) to use my template?

You can use hook_theme_registry_alter()

Here is an example of its use in a custom module that works for me (Just replace 'mymodule' with the name of your module):

/**
 * Implementation of hook_theme_registry_alter()
 */
function mymodule_theme_registry_alter(&$theme_registry) {
  $template = 'node';
  $originalpath = array_shift($theme_registry[$template]['theme paths']);
  $modulepath = drupal_get_path('module', 'mymodule');
  // Stick the original path with the module path back on top
  array_unshift($theme_registry[$template]['theme paths'], $originalpath, $modulepath);
}

Now, Drupal will check your module folder for node template overrides.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM