--- phptemplate.engine.orig	2008-07-10 16:11:48.000000000 -0400
+++ phptemplate.engine	2008-07-10 17:37:26.000000000 -0400
@@ -116,6 +116,19 @@ function _phptemplate_default_variables(
         isset($variables[$region]) ? $variables[$region] .= theme('blocks', $region) : $variables[$region] = theme('blocks', $region);
       }
     }
+    ///set these variables late, so block calls can add headers
+    if (!isset($variables['css'])) {
+      $variables['css'] = drupal_add_css();
+    }
+    if (!isset($variables['styles'])) {
+      $variables['styles'] = drupal_get_css();
+    }
+    if (!isset($variables['scripts'])) {
+      $variables['scripts'] = drupal_get_js();
+    }
+    if (!isset($variables['head'])) {
+      $variables['head'] = drupal_get_html_head();
+    }
   }
   // Tell all templates where they are located.
   $variables['directory'] = path_to_theme();
@@ -198,7 +211,6 @@ function phptemplate_page($content, $sho
     'content'             => $content,
     'feed_icons'          => drupal_get_feeds(),
     'footer_message'      => filter_xss_admin(variable_get('site_footer', FALSE)) . "\n" . theme('blocks', 'footer'),
-    'head'                => drupal_get_html_head(),
     'head_title'          => implode(' | ', $head_title),
     'help'                => theme('help'),
     'language'            => $GLOBALS['locale'],
@@ -213,9 +225,6 @@ function phptemplate_page($content, $sho
     'sidebar_right'       => $sidebar_right,
     'site_name'           => (theme_get_setting('toggle_name') ? variable_get('site_name', 'Drupal') : ''),
     'site_slogan'         => (theme_get_setting('toggle_slogan') ? variable_get('site_slogan', '') : ''),
-    'css'                 => drupal_add_css(),
-    'styles'              => drupal_get_css(),
-    'scripts'             => drupal_get_js(),
     'tabs'                => theme('menu_local_tasks'),
     'title'               => drupal_get_title()
   );
