summaryrefslogtreecommitdiff
path: root/themes/engines/phptemplate/phptemplate.engine
diff options
context:
space:
mode:
authorNeil Drumm <drumm@3064.no-reply.drupal.org>2006-07-27 08:01:58 +0000
committerNeil Drumm <drumm@3064.no-reply.drupal.org>2006-07-27 08:01:58 +0000
commit589e9f237fbf27698e377e3be08599b3b322148c (patch)
treece097f1ff8dae699194a0fc952d675cacf4a33e6 /themes/engines/phptemplate/phptemplate.engine
parent1a88d134b88a7bfb17b164bd03ace7aa3190b185 (diff)
downloadbrdo-589e9f237fbf27698e377e3be08599b3b322148c.tar.gz
brdo-589e9f237fbf27698e377e3be08599b3b322148c.tar.bz2
#65706 by Eaton, look for page templates based upon the path.
Diffstat (limited to 'themes/engines/phptemplate/phptemplate.engine')
-rw-r--r--themes/engines/phptemplate/phptemplate.engine52
1 files changed, 38 insertions, 14 deletions
diff --git a/themes/engines/phptemplate/phptemplate.engine b/themes/engines/phptemplate/phptemplate.engine
index e081cd477..7dc1254ea 100644
--- a/themes/engines/phptemplate/phptemplate.engine
+++ b/themes/engines/phptemplate/phptemplate.engine
@@ -46,12 +46,13 @@ function phptemplate_regions() {
* The name of the theme function being executed.
* @param $variables
* A sequential array of variables passed to the theme function.
- * @param $file
- * A suggested template file to use. If the file is not found, the default $hook.tpl.php will be used.
+ * @param $suggestions
+ * An array of suggested template files to use. If none of the files are found, the
+ * default $hook.tpl.php will be used.
* @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 +63,21 @@ function _phptemplate_callback($hook, $variables = array(), $file = NULL) {
$variables = array_merge($variables, call_user_func($variables_function, $hook, $variables));
}
+ if (is_array($variables['template_files'])) {
+ $suggestions = array_merge($suggestions, $variables['template_files']);
+ }
+
if (isset($variables['template_file'])) {
- $file = $variables['template_file'];
+ $suggestions[] = $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 +219,20 @@ function phptemplate_page($content) {
$variables['node'] = node_load(arg(1));
}
- return _phptemplate_callback('page', $variables);
+ $i = 0;
+ $suggestion = 'page';
+ $suggestions = array($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);
}
/*
@@ -256,7 +274,7 @@ function phptemplate_node($node, $teaser = 0, $page = 0) {
$variables['picture'] = '';
}
- return _phptemplate_callback('node', $variables, 'node-' . $node->type);
+ return _phptemplate_callback('node', $variables, array('node-' . $node->type));
}
/**
@@ -311,16 +329,22 @@ function phptemplate_box($title, $content, $region = 'main') {
* The name of the theme function being executed.
* @param $variables
* A sequential array of variables passed to the theme function.
- * @param $file
- * A suggested template file to use.
+ * @param $suggestions
+ * An array of suggested template files 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";
}