I have a custom node.tpl.php and i'm working on creating a custom page.tpl.php, my question is this:

is there a more logical way to name your page.tpl.php files? for example, a custom node for cck type about would be:

node-about.tpl.php

and the page would be:

page-node-150.tpl.php

is there away to reference the content type in the page.tpl.php name like:

page-node-about.tpl.php

i've been trying names and nothing seems to work.

Comments

lyricnz’s picture

The reason that your new templates do not work, is that there is a strict list of filenames that are checked. This is described in phptemplate_page() in phptemplate.engine:

  // Build a list of suggested template files in order of specificity. One
  // suggestion is made for every element of the current path, though
  // numeric elements are not carried to subsequent suggestions. For example,
  // \http://www.example.com/node/1/edit would result in the following
  // suggestions:
  //
  // page-node-edit.tpl.php
  // page-node-1.tpl.php
  // page-node.tpl.php
  // page.tpl.php

However, all is not lost: when the framework does the actual templating, this list is passed, but your theme is able to add suggestions to the list! You can do this, by implementing/adding the function _phptemplate_variables() in your theme. Something like this:

function _phptemplate_variables($hook, $vars) {
  if ($hook == 'page') {
    $vars['template_files'] = array('page-node-'. $vars['node']->type);
    return $vars;
  }
}

You suggestions (page-node-story for example) will be used BEFORE the other suggestions. Make sure you don't damage the code that already exists in this function! (by returning from the function too early, by example). Phew! This answer took longer than expected!

kliertje’s picture

code above did not work... but with a wee tweak it did. See here under:

<?php
function _phptemplate_variables($hook, $vars) {
	if ($hook == 'page') {
		$vars['template_files'] = array('page-'. $vars['node']->type);
	}
	return $vars; /* return $vars; goes here*/
}
?>
lyricnz’s picture

Yes, I did my testing using garland, which has a bunch more code in that function. That depends on your theme etc. That's why I included the comment "Make sure you don't damage the code that already exists in this function! (by returning from the function too early, by example)". Good luck!