Running Drupal 6.20, am preparing a custom module set for publishing to community. These modules (MYMODULE) programmatically create CCK types (MYNODE)that we have been using custom templates to theme [node-mynode.tpl.php in the standard theme directory].
What I'd like to do is include with the module a default template [node-mynode.tpl.php] that is included in the mymodule/themes directory that would be used in the absence of a custom template in the theme directory. So, the priority would be:
- Default node-mynode.tpl.php provided in mymodule/themes
- Any other node-mynode.tpl.php that they would want to use to override my default by placing in the standard theme folder
It seems that what I'm looking for was described and commented on http://11heavens.com/theming-Drupal-6-from-the-module-layer and http://drupal.org/node/296871 , but I can't get those processes to work.
My code, which assumes the existence of a CCK-based node type called MYNODE and an already existing [theme based] node-mynode.tpl.php.
function mymodule_preprocess_node(&$vars) {
// drupal_set_message('node preprocess);
$vars['template_file'][] = 'node-mynode';
}
function mymodule_theme_registry_alter(&$theme_registry) {
// print_r($theme_registry);
$template = "node-mymodule";
if (is_array($theme_registry['template_files'][$template])) {
drupal_set_message($theme_registry['template_files']);
$originalpath = array_shift($theme_registry[$template]['theme paths']);
$modulepath = drupal_get_path('module', 'mymodule') . '/templates';
array_unshift($theme_registry[$template]['theme paths'], $originalpath, $modulepath);
}
}
Now, I've read that after 6.7, the theme_registry_alter system is no longer necessary, but I can't get this behaviour regardless of it's presence or absence. (http://drupal.org/node/223430). Potentially this can be accomplished through mymodule_theme as http://drupal.org/node/342350 suggests?
What would then be the correct interpretation? Something like: ?
function MYMODULE_theme(){
return array(
'node_MYNODE'=> array(
'template'=>'node-MYNODE',
)
);
}
function MYMODULE_menucallback(){
return theme('node_MYNODE');
}
Comments
Solution?
I seem to have achieved the functionality I want through the following code, utilizing hook_theme to define a path for node templates. The behaviour achieved is to look in my template directory for the initial template, and override by placing directly in the theme directory.
Kosher solution?
not the best solution to be
not the best solution to be honest,
this will overwrite the default path for node.tpl.php, so if the theme does not have node.tpl.php it will trigger an array
This will consider looking into mymodule/templates for node-mycontent-type.tpl.php
My personal blog | twitter:@sotak
Better!
Very much appreciated Marek.
Thats the tweak on my original attempt that I'd been looking for - how on earth did you know to append "type" in the code below? I couldn't find that illumination in any of the documentation I stared at.
Drupal 7 solution
I know this is an old thread, but wanted to add this for anyone who stumbles across this thread looking to do this in D7. The solution below is from http://www.metachunk.com/blog/adding-module-path-drupal-7-theme-registry.
+1
+1
This issue is also very
This issue is also very helpful in these matters: http://drupal.org/node/303586