Changing page.tpl based on node type

Today I needed to add a new candidate page.tpl file based on node-type. I found this code snippet and modified it slightly.

function phptemplate_preprocess(&$vars, $hook) {
	switch ($hook){
		case 'page':
		  // Add a content-type page template in second to last.	
			if ('node' == arg(0)) {
				$node_template = array_pop($vars['template_files']);
				$vars['template_files'][]  = 'page-' . $vars['node']->type;
				$vars['template_files'][]  = $node_template;
			}
			break;
	}
	return $vars;
}

My tweak puts the new template in the middle of the candidate templates array so that I can still have specific page.tpl files for specific nodes. The devel module tells me my candidate files are now:

page-node-4.tpl.php < page-story.tpl.php < page-node.tpl.php < page.tpl.php

This works on Drupal 6.

This is a very cool tip,

This is a very cool tip, brother

Drupal 6

I don't see any function named like this in template.php
I found a phptemplate_preprocess_page, though.

Should i replace the one I found or add the one you provide beside it ?

Thanks.

Nope. Just create this

Nope. Just create this function and Drupal will find it.

Thank you

This helped me greatly today. Much appreciated.

Its important to remind

Its important to remind people that they need to clear the drupal cache before they will see any changes.
admin/settings/performance

Thanks and an echo

Thanks, this worked wonderfully in Drupal 6 after I cleared my cached files under admin/settings/performance

Helpful

Thanks for posting this... it was very helpful! Especially the reminder to clear your cache.

Amazing formula to render the layout drupal content-type wise

Hye Floydm,

This is the great formula that I appreciated to look for the drupal.

I've updated the drupal 6.4 to 6.10 which is the latest release of the drupal nowadays.In 6.10, the development team has fixed some issues which had been presented in the prior release of the drupal.

I read through the internet to render the layout node's content type wise. It says that, "node-[content-type].tpl.php" will render the layout, node's content-type wise. But it won't work. I also tried to use page.[content-type].tpl.php without implementing your function in template.php file.

Many thanks,

Web-Farmer
http://www.letsnurture.com

Thank you

awesome!

Thanks!

Awesome... saved the day!

Thanks,
BC

Brilliant! Exactly what I

Brilliant! Exactly what I needed, many thanks.

Thanks for posting this... it

Thanks for posting this... it was very helpful! Especially the reminder to clear your cache.

Thank you!

I'd been looking for something like this, and this is the answer to my problems. Thank you! This is AWESOME!

Great tip

Thanks for sharing this, great tip!

Be aware that this is not

Be aware that this is not name-spaced, so you may find unexpected effects. Take, for example, the forums.

If I add a template file "page-forum" this will match both the system path for forums AND the node type of forum, as Drupal's template system is preconfigured to look for page template matches based upon system (non-aliased) path.

This may be useful (in fact in the example i give it was useful) but it may be undesirable.

To make it a little safer you could make it more specific:


$vars['template_files'][] = 'page-nodetype-' . $vars['node']->type;

This would require you to use a template file of page-nodetype-forum.tpl.php, eliminating the name clash.

Thank you very much for the

Thank you very much for the excellent and useful subject.

Thank you very much for the

Thank you very much for the excellent and useful subject.

well described

very useful.well answered for the problem.

Re

That will be the big favour for the thesis writing service to take your cool thought connected with this good post for the dissertation tips performing. So, all the scholars will have an opportunity to buy the premium level english dissertation.

Hi, Very interesting article

Hi,
Very interesting article will bookmark your site to check if you write more about in the future.

Custom Term Paper

Re

The essay writing just about this topic, the students will find at the writing services. Buy the research paper and custom essay just about this post.

alisacaksina

second oldest player on the 2008 Team's roster. The Redeem Team has six players 24 years old or younger. sohpet ekranda gördugun sohbet odaları travesti evden eve nakliyatget rid of the ball if he was within ten feet of me travestiler about my experience playing against Travis Ford travesti sikiş Travis Ford. I quickly learned toporno izle porno izle my experience playing against porno sikiş were writing aboutOh, and the beauty of it all is that I get to claim my site is "serious" herşey cok cuz news,sikiş porno izle because we pirate stories from all the big papers, slap a new lead on them and sex izle pornoone of our gratis-faux "journalist's" mugshots and try to call it our own original chat sohbetThank you very much for this information. chatGood post thanks for sharing.chat odalarıI like this site ;)Good article, Some have served their entire adult lives--30-35 years--at one nedenni ormanewspaper. Seems like the wrong people are ashamed. rn salary porno izlesikişSome nasty comments for a fairly serious subject. That's unfortunate.porno izleI don't think anyone has a clear idea of what's going to happen, but you're right sikişabout the fact that journalists aren't doing anything about it. That's only that somebody or something comes along and saves them, ala, the automobile chat chat odalarıFact is, printed media needs to die so that it can be reborn, so the business porno izlemodel adjusts into something that works. maynetporno izleThey appear to be holdingporno They appearsikiş yes branda branda tente brandaterazibaskülçelik kasaelektronik tartıelektronik terazitartı terazi yıklatartı travesti tente maynet chat sohbet sikiş evden eve kayseri evden eve nakliyat kayseri Red Pepper Red Pepper zayıflama hapı
Solea Solea zayıflama zayıflama zayıflama geciktirici geciktirici sprey geciktirici geciktirici sprey geciktirici hap bitkisel ürün bitkisel ürünler güzellik güzellik sırları

It's not the GM's, or the Coach's fault for drafting a player who turns out to be a bust, but 9/10 times "except in Elgian Baylors case,

BBC

I believe the information covered in the discussion is top notch. I've been doing a research on the subject and your blog just cleared up a lot of questions. I am working on a custom essay and custom essays for my English class and currently reading lots of blogs to study.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <b> <blockquote>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.