Index: phptemplate.engine =================================================================== --- phptemplate.engine (revision 624) +++ phptemplate.engine (working copy) @@ -220,9 +220,8 @@ 'title' => drupal_get_title() ); - if ((arg(0) == 'node') && is_numeric(arg(1))) { - $variables['node'] = node_load(arg(1)); - } + if ($node = _phptemplate_cache('node')) + $variables['node'] = $node; // Build a list of suggested template files in order of specificity. One // suggestion is made for every element of the current path, though @@ -289,6 +288,10 @@ $variables['picture'] = ''; } + if ($page) + // Cache the node object so that phptemplate_page may refer to it. + _phptemplate_cache('node', $node); + return _phptemplate_callback('node', $variables, array('node-' . $node->type)); } @@ -396,4 +399,15 @@ return $contents; // Return the contents } +/** + * Cache variables for the duration of one page render. This is useful when + * more than one of phptemplate's hooks needs to access the same data. + */ +function _phptemplate_cache($key, $value = NULL) { + static $cache = array(); + if (isset($value)) { + $cache[$key] = $value; + } + return $cache[$key]; +} ?>