Aprium Software

Theming a node from your modules dir

Im currently building a contractors book keeping module to store invoices. I have a new content type and I wanted to theme that new node type from a template in my modules directory. But I also wanted to allow the user to override the template with one in there theme directory if they wished.

After a while of trying different search terms in google I managed to find an article on the matter.

http://shellmultimedia.com/articles/hookthemeregistryalter-advanced-template-control

This article uses a drupal 6 hook I have never heard of called hook_theme_registry_alter(). He uses it to add your module directory in the theme registery so it looks for templates in our module directory then overrides them in the theme directory.

Here is his example which I have edited specifically for node templates. The only thing you have to do is replace [module] with the name of your module in 2 places.

function [module]_theme_registry_alter($theme_registry) {		
	// Remove the first path under 'node' which is the one for the
	// module that created the template	
	$originalpath = array_shift($theme_registry['node']['theme paths']);	

	// Get the path to your module						
	$modulepath = drupal_get_path('module', '[module]');

	// Stick the original path and then your module path back on top	
	array_unshift($theme_registry['node']['theme paths'], $originalpath, $modulepath);

}

Hire

If you need a London based Drupal developer you can hire me. Check the availability page and contact me on info@aprium.net.

 

Powered by Drupal, an open source content management system

Copyright Aprium 2010