2011-05-27 127 views
8

我有一个添加新内容类型的模块。Drupal 6 - 模块中的自定义节点类型模板

对于此内容类型我想提供一个node_contenttype.tpl.php节点类型模板, 但Drupal无法在模块目录中识别此模板,只能在主题中识别。

如何获得Drupal(6)使用我的模板?

回答

10

您可以使用hook_theme_registry_alter()

下面是它为我的作品自定义模块中使用的实例(只需用模块的名称替换“MyModule的”):

/** 
* 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); 
} 

现在, Drupal将检查您的模块文件夹中的节点模板覆盖。

+0

适合我。 – theduke 2011-07-27 13:56:36