I created a module to provide a special *page* template for a content type, namely the 'webform' content type.
When a 'webform' node is shown on its dedicated page, I want a special template,page-webform.tpl.php
, to be used to output my page markup.
My module is very simple, it uses a preprocess function to add a suggestion based on the type of node shown on a node page.
Here's the code:
function iframe_contact_preprocess_page(&$variables) {
// $variables['node'] is set only on a node page
if (isset($variables['node']) && $variables['node']->type == 'webform') {
$variables['template_file'] = 'page-webform';
}
}
My problem is that when I place the template file inside the module folder it is not seen by the theme engine. The template is seen (and used) only when I place it in my active theme folder.
Is there anything I am missing here?
Thanks in advance.
Comments
subscribe
subscribe
Drupal samurai for hire, based in Buffalo, New York, USA.
15+ years Drupal, 20+ years web.
http://basicmagic.net
Have you tried
Have you tried hook_theme_registry_alter() ?
A little googling found a few articles. This one by michelle is pretty good.
http://shellmultimedia.com/articles/hookthemeregistryalter-advanced-temp...
Hey thanks a lot! This is
Hey thanks a lot!
This is *exactly* what I was needing. Except..
Not sure if this is kosher... but I will give this code a try and report back.
Caroline
11 heavens.com
Two problems with Michelle's code
$theme_registry is not passed by reference, so any changes made to that variable will be lost.
$template has not been set, it needs to be set to 'page' in my case.
And when I correct these, it works!
Here is the corrected code (replace capitals with what is relevant in your situation):
Caroline
11 heavens.com
Better code maybe
This code can even be more succinct...
There are issues of performance here probably though, that hook is always called...
I decided to blog about this: http://11heavens.com/theming-Drupal-6-from-the-module-layer
Caroline
11 heavens.com
Possible in Drupal 5
I'd like to do the same basic thing in Drupal 5. Theme a particular node type a specific way, without relying on the user to move any code over into their theme folder.
Is this possible in Drupal 5 at the module level? I've noticed, for instance, that the panels module disables blocks on certain admin pages, which seems very useful to me. Actually I want to disable all content for the node/add/mynodetype pages, except what my module produces.
Dave
My site: http://www.unitorganizer.com/myblog
Hi Dave
I would like to know this as well.
Caroline
11 heavens.com
Supposed to be possible using a 'hack'
This is supposed to be possible using a hack. Basically you create a function, call it phptemplate_page and use that function to theme the node appropriately, but this seems to me to creating the problem that a user can destroy my module's functionality just by wanting to use the same function in their template.php file.
I'm hopeful that there is another way?
Dave
My site: http://www.unitorganizer.com/myblog
Called
I wanted to add: that hook is *not* always called, it gets called when the theme registry is rebuilt (ie: when cache is cleared).
Caroline
11 heavens.com
Related q/update
I've posted a forum issue that's very much related, since this technique doesn't seem to be applicable in 6.20. Any thoughts?
http://drupal.org/node/1105922
Resolved.
Forum contains the resolution for this issue, much thanks. http://drupal.org/node/1105922