--- contemplate/contemplate.module.old	Sat Apr 02 17:50:30 2011
+++ contemplate/contemplate.module	Thu Apr 21 10:36:55 2011
@@ -253,6 +253,13 @@
     $default_body = "<?php print \$body ?>\n";
   }
 
+  $form['needednid'] = array(
+    '#type'				=> 'textfield',
+    '#title'			=> t('Node ID to load'),
+    '#default_value'	=> isset($_SESSION['contemplatenid']) ? intval($_SESSION['contemplatenid']) : '',
+  );
+ 
+
   $form['teaser'] = array(
     '#type'             => 'fieldset',
     '#title'            => t('Teaser'),
@@ -496,12 +503,25 @@
 }
 
 function contemplate_edit_type_form_submit($form, &$form_state) {
+  
+  unset($_SESSION['contemplatenid']);
+
   $op = isset($_POST['op']) ? $_POST['op'] : '';
   if ($op == t('Delete')) {
     contemplate_delete($form_state['values']['type']);
     drupal_set_message(t('%type template has been reset.', array('%type' => drupal_ucfirst($form_state['values']['type']))));
   }
   else {
+    if(isset($form_state['values']['needednid']) && ($nid = intval($form_state['values']['needednid'])) != 0)    {
+      $node = node_load($nid);
+      if($node->type == $form_state['values']['type']) {
+        $_SESSION['contemplatenid'] = $nid;
+      }
+      else {		
+        drupal_set_message(t('The node with NID you provided does not exist or its type differs from the template type.'));
+      }
+    }
+  
     contemplate_save($form_state);
     drupal_set_message(t('%type template saved.', array('%type' => drupal_ucfirst($form_state['values']['type']))));
   }
@@ -622,7 +642,14 @@
  */
 function contemplate_node_views($type) {
   // get the nid of the latest node of this type
-  $result = db_query("SELECT nid FROM {node} WHERE type = :type ORDER BY created DESC", array(':type' => $type->type));
+  if(isset($_SESSION['contemplatenid']))
+  {
+    $result = db_query("SELECT nid FROM {node} WHERE nid= :nid AND type = :type ORDER BY created DESC", array(':nid'=>intval($_SESSION['contemplatenid']), ':type' => $type->type));
+  }
+  else
+  {
+    $result = db_query("SELECT nid FROM {node} WHERE type = :type ORDER BY created DESC", array(':type' => $type->type));
+  }
   foreach ($result as $record) {
     $nid = $record->nid;
   }
