Skip to main content

Drupal 6 Custom content type page theme

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:

  1. /**
  2.  * Override or insert PHPTemplate variables into the templates.
  3.  */
  4. function phptemplate_preprocess_page(&$vars) {
  5.   // Add per content type pages
  6.   if (isset($vars['node'])) {
  7.     // Add template naming suggestion. It should alway use hyphens.
  8.     // If node type is "custom_news", it will pickup "page-custom-news.tpl.php".
  9.     $vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
  10.   }
  11. }

Thanks dvessel

Thank you!!

Thank you!!

hhm... its not working for

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

This worked greart for me.

This worked greart for me. I've been looking for hours!

Thank you thank you thank

Thank you thank you thank you! What an elegant and slim solution, just what I needed!

many thanks

many thanks

Don't forget to Clear Cache!

Don't forget to Clear Cache!

Thank you so much, I have

Thank you so much, I have been trying to solve this problem for hours now!

Cheers!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
2 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.

If you need more help on the topic feel free to add a comment or create a new post on the Forum