If you ever wondered how to change the page.tpl.php for a custom content type you've found out that by default Drupal 6 doesn't know how to do it.
It's "fixed" easily by adding the following code:
/**
* Override or insert PHPTemplate variables into the templates.
*/
function phptemplate_preprocess_page(&$vars) {
// Add per content type pages
if (isset($vars['node'])) {
// Add template naming suggestion. It should alway use hyphens.
// If node type is "custom_news", it will pickup "page-custom-news.tpl.php".
$vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
}
}
Thanks dvessel
Comments
Thank you!!
Submitted by Code Monkey (not verified) on
Thank you!!
Thanks, I found this very
Submitted by Code Monkey (not verified) on
Thanks, I found this very helpful.
Entering the original function as is breaks many portions of the admin section, but if you rename the "phptemplate" portion of the function name to "mysite" where it is the name of your site it works perfectly.
The recommended way is to
Submitted by CoolGoose on
The recommended way is to replace "phptemplate" with the name of your theme.
hhm... its not working for
Submitted by Code Monkey (not verified) on
hhm... its not working for me. i have a content type 'affiliate' and wanted to call a template 'page-node-affiliate.tpl.php' base on node type('affiliate').
i only received a blank page...
please help...
thanks,
vsotto
You've got the wrong naming
Submitted by Code Monkey (not verified) on
You've got the wrong naming convention. You can create a template for a page and/or a node. If you want a page, then it's page-[name].tpl.php and if you want to only change the node layout then you need to use node-[name].tpl.php
This worked greart for me.
Submitted by John Larysz on
This worked greart for me. I've been looking for hours!
Thank you thank you thank
Submitted by Code Monkey (not verified) on
Thank you thank you thank you! What an elegant and slim solution, just what I needed!
many thanks
Submitted by Code Monkey (not verified) on
many thanks
Don't forget to Clear Cache!
Submitted by Code Monkey (not verified) on
Don't forget to Clear Cache!
Thank you so much, I have
Submitted by Code Monkey (not verified) on
Thank you so much, I have been trying to solve this problem for hours now!
Cheers!
Worked like a charm...
Submitted by Code Monkey (not verified) on
Worked like a charm... Thanks!
That is a deadly "Empty
Submitted by Code Monkey (not verified) on
That is a deadly "Empty Cache". Waste sometime before I found @cool_qosys comment.
Bloody marvelous! Thanks!
Submitted by Code Monkey (not verified) on
Bloody marvelous!
Thanks!
Third class
Submitted by Code Monkey (not verified) on
Third class
Awesome great post !
Submitted by Code Monkey (not verified) on
Awesome great post !
Thank you! Worked smoothly!
Submitted by Code Monkey (not verified) on
Thank you! Worked smoothly!
thanks worked perfectly
Submitted by Code Monkey (not verified) on
thanks worked perfectly
HELP!. It works but replaces
Submitted by Code Monkey (not verified) on
HELP!. It works but replaces the entire page template with the new template. I just want to replace the content portion of it, thus keeping header, footer, etc.
Any ideas?
thanks
node-[name].tpl.php
Submitted by CoolGoose on
node-[name].tpl.php
Sorry I was not completeley
Submitted by Code Monkey (not verified) on
Sorry I was not completeley specific.
node-[name].tpl.php works for content types but not for taxonomy terms which is my problem. and all the solutions I have tried replace the entire page code not just the content portion of it.
thanks a lot.
Ah, unfortunately you can't
Submitted by CoolGoose on
Ah, unfortunately you can't do that easily.
One solution would be to split your existing page.tpl in header/footer parts and include them.
Got It! Thanks a lot for your
Submitted by Code Monkey (not verified) on
Got It!
Thanks a lot for your answer, however I just figured out the answer to my problem, in case anybody is looking for the same issue here's what I did:
function mysite_preprocess_page(&$vars, $hook){
if($hook == 'page' && arg(0) == 'taxonomy' && arg(1) == 'term'){
$vars['content'] = theme('custom_node_taxonomy', $vars['content']);
}
}
and then implement the selected theme into the mysite_theme()
Now I can use my custom tpl to edit term pages. Maybe not the most efficient solution but works fine
cheers.
Thanks a lot for the update
Submitted by CoolGoose on
Thanks a lot for the update ;). Nice snippet.
Pages
Add new comment