Index: themes/engines/phptemplate/phptemplate.engine
===================================================================
RCS file: /cvs/drupal/drupal/themes/engines/phptemplate/phptemplate.engine,v
retrieving revision 1.35
diff -u -r1.35 phptemplate.engine
--- themes/engines/phptemplate/phptemplate.engine	7 May 2006 00:08:36 -0000	1.35
+++ themes/engines/phptemplate/phptemplate.engine	5 Jun 2006 21:39:26 -0000
@@ -51,7 +51,7 @@
  * @return
  *  The HTML generated by the template system.
  */
-function _phptemplate_callback($hook, $variables = array(), $file = NULL) {
+function _phptemplate_callback($hook, $variables = array(), $suggestions = array()) {
   global $theme_engine;
 
   $variables = array_merge($variables, _phptemplate_default_variables($hook, $variables));
@@ -62,17 +62,21 @@
     $variables = array_merge($variables, call_user_func($variables_function, $hook, $variables));
   }
 
+  if (isset($variables['template_files'])) {
+    $suggetions = $variables['template_files'];
+  }
+
   if (isset($variables['template_file'])) {
-    $file = $variables['template_file'];
+    $suggetions[] = $variables['template_file'];
   }
 
   $hook_function = '_'. $theme_engine .'_'. $hook;
   $default_function = '_'. $theme_engine .'_default';
   if (function_exists($hook_function)) {
-    return call_user_func($hook_function, $variables, $file);
+    return call_user_func($hook_function, $variables, $suggestions);
   }
   elseif (function_exists($default_function)) {
-    return call_user_func($default_function, $hook, $variables, $file);
+    return call_user_func($default_function, $hook, $variables, $suggestions);
   }
 
 }
@@ -214,7 +218,20 @@
     $variables['node'] = node_load(arg(1));
   }
 
-  return _phptemplate_callback('page', $variables);
+  $i = 0;
+  $suggestion = 'page';
+  $suggestions[] = $suggestion;
+  while ($arg = arg($i++)) {
+    $suggestions[] = $suggestion . '-' . $arg;
+    if (!is_numeric($arg)) {
+      $suggestion .= '-' . $arg;
+    }
+  }
+  if (drupal_is_front_page()) {
+    $suggestions[] = 'page-front';
+  }
+  
+  return _phptemplate_callback('page', $variables, $suggestions);
 }
 
 /*
@@ -255,7 +272,7 @@
     $variables['picture'] = '';
   }
 
-  return _phptemplate_callback('node', $variables, 'node-' . $node->type);
+  return _phptemplate_callback('node', $variables, array('node-' . $node->type));
 }
 
 /**
@@ -313,13 +330,19 @@
  * @param $file
  *   A suggested template file to use.
  */
-function _phptemplate_default($hook, $variables, $file = NULL, $extension = '.tpl.php') {
+function _phptemplate_default($hook, $variables, $suggestions = array(), $extension = '.tpl.php') {
   global $theme_engine;
 
-  if (!empty($file) && file_exists(path_to_theme() ."/$file$extension")) {
-    $file = path_to_theme() ."/$file$extension";
+  // loop through any suggestions in FIFO order
+  $suggestions = array_reverse($suggestions);
+  foreach($suggestions as $suggestion) {
+    if (!empty($suggestion) && file_exists(path_to_theme() ."/$suggestion$extension")) {
+      $file = path_to_theme() ."/$suggestion$extension";
+      break;
+    }
   }
-  else {
+
+  if (!isset($file)) {
     if (file_exists(path_to_theme() ."/$hook$extension")) {
       $file = path_to_theme() ."/$hook$extension";
     }
@@ -349,4 +372,4 @@
   return $contents;                // Return the contents
 }
 
-?>
+?>
\ No newline at end of file
