Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sections/README.txt,v
retrieving revision 1.2.2.5
diff -u -r1.2.2.5 README.txt
--- README.txt	13 Dec 2009 11:48:23 -0000	1.2.2.5
+++ README.txt	19 Sep 2010 11:26:57 -0000
@@ -17,15 +17,20 @@
 characters not in [A-Za-z0-9] will be truncated to a hyphen. The suggested 
 template names are:
 
-  block-sections-[section id].tpl.php
+  block-sections-node-[nid].tpl.php
+  block-sections-path-[section id].tpl.php
   block-sections-[section name].tpl.php
-  node-sections-[section id].tpl.php
+
+  node-sections-node-[nid].tpl.php
+  node-sections-path-[section id].tpl.php
   node-sections-[section name].tpl.php
-  page-sections-[section id].tpl.php
+
+  page-sections-node-[nid].tpl.php
+  page-sections-path-[section id].tpl.php
   page-sections-[section name].tpl.php
 
 Examples:
-1. Section has the id 5 -> suggested page template is "page-sections-5.tpl.php".
+1. Section has the ID 5 -> suggested page template is "page-sections-path-5.tpl.php".
 2. Section is named "My blue forum" -> suggested page template is "page-sections-my-blue-forum.tpl.php".
 
 
Index: sections.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/sections/sections.module,v
retrieving revision 1.21.2.33
diff -u -r1.21.2.33 sections.module
--- sections.module	19 Sep 2010 11:26:17 -0000	1.21.2.33
+++ sections.module	19 Sep 2010 11:26:58 -0000
@@ -165,15 +165,6 @@
         db_query('DELETE FROM {sections_nodes} WHERE nid = %d', $node->nid);
       }
       break;
-
-    case 'view':
-      // TODO: Only switch the theme if the node is viewed as page and not in teaser mode.
-
-      // If node specific theme is configured, switch to node theme.
-      if (!empty($node->sections['theme'])) {
-        _sections_switch_theme($node->sections['theme']);
-      }
-      break;
   }
 }
 
@@ -284,6 +275,21 @@
   }
   else {
     // Caller wants to know in which section she is.
+
+    // If node specific theme is configured, switch to that theme.
+    if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
+      $row = _sections_node_cache_get(arg(1));
+      if (!empty($row->theme)) {
+        if (variable_get('sections_debug', FALSE)) {
+          // DEBUG message for easier self analysis which theme has been matched.
+          // Never use % placeholder or init_theme get's executed and theme switch fails.
+          drupal_set_message(t('DEBUG_MATCH_DETECT: Found node #@nid specific section for path "@path" with theme "@theme".', array('@theme' => $row->theme, '@path' => 'node/'. $row->nid, '@nid' => $row->nid)), 'status', FALSE);
+        }
+        return $row;
+      }
+    }
+
+    // Otherwise, see if one of the defined sections matches.
     $rids = array_keys($user->roles);
     $res = _sections_path_cache_get($rids);
     foreach ($res as $sid => $row) {
@@ -325,6 +331,37 @@
 }
 
 /**
+ * An internal caching function that statically caches the node based sections.
+ *
+ * @param $nid
+ *   The node id.
+ * @param $reset
+ *   Manually resets the node sections cache.
+ * @return
+ *   Cached node sections data.
+ */
+function _sections_node_cache_get($nid, $reset = FALSE) {
+  static $sections = array();
+
+  // Kill all cached node sections data.
+  if ($reset) {
+    $sections = array();
+  }
+
+  if (!isset($sections[$nid])) {
+    // Fill array with node section. Collect only one nid at once for
+    // performance reasons, otherwise we would get too many nid's.
+    $result = db_query("SELECT * FROM {sections_nodes} WHERE nid = %d", $nid);
+    while ($row = db_fetch_object($result)) {
+      $sections[$row->nid] = $row;
+    }
+  }
+
+  // Return cached node sections data.
+  return $sections[$nid];
+}
+
+/**
  * An internal caching function that statically caches the path based sections.
  *
  * @param $rids
@@ -366,30 +403,36 @@
 
     // Add some section information to all preprocess hooks.
     $variables['section'] = array(
-      'sid' => $section->sid,
       'theme' => $section->theme,
       'name_clean' => $name_clean,
     );
 
+    if (isset($section->nid)) {
+      $variables['section']['key'] = 'node-' . $section->nid;
+    }
+    elseif (isset($section->sid)) {
+      $variables['section']['key'] = 'path-' . $section->sid;
+    }
+
     switch ($hook) {
       case 'page':
         // Add template suggestions for page templates.
         $variables['template_files'][] = 'page-sections';
-        $variables['template_files'][] = 'page-sections-'. $section->sid;
+        $variables['template_files'][] = 'page-sections-'. $variables['section']['key'];
         $variables['template_files'][] = 'page-sections-'. $name_clean;
         break;
 
       case 'node':
         // Add template suggestions for node templates.
         $variables['template_files'][] = 'node-sections';
-        $variables['template_files'][] = 'node-sections-'. $section->sid;
+        $variables['template_files'][] = 'page-sections-'. $variables['section']['key'];
         $variables['template_files'][] = 'node-sections-'. $name_clean;
         break;
 
       case 'block':
         // Add template suggestions for block templates.
         $variables['template_files'][] = 'block-sections';
-        $variables['template_files'][] = 'block-sections-'. $section->sid;
+        $variables['template_files'][] = 'page-sections-'. $variables['section']['key'];
         $variables['template_files'][] = 'block-sections-'. $name_clean;
         break;
     }
