Index: pi/class.tx_ttnews.php
===================================================================
--- pi/class.tx_ttnews.php	(revision 11051)
+++ pi/class.tx_ttnews.php	(working copy)
@@ -644,6 +652,8 @@
 
 				// Add to content
 				$searchSub = $this->getNewsSubpart($this->templateCode, $this->spMarker('###TEMPLATE_SEARCH###'));
+                		$markers = $this->getMarkers($searchSub);
+                		$this->renderMarkers = array_unique($markers);
 				$content .= $this->cObj->substituteMarkerArray($searchSub, $searchMarkers);
 				unset($searchSub);
 				unset($searchMarkers);
@@ -763,13 +774,20 @@
 				// $t['item'] is an array with the alternative subparts (NEWS, NEWS_1, NEWS_2 ...)
 				$t = array();
 				$t['total'] = $this->getNewsSubpart($this->templateCode, $this->spMarker('###' . $templateName . '###'));
-
+                
 				$t['item'] = $this->getLayouts($t['total'], $this->alternatingLayouts, 'NEWS');
+                		// Parse out markers in the templates to prevent unnecessary queries and code from executing
+                		$markers = $this->getMarkers($t['total']);
+                		foreach($t['item'] as $item)
+                    		$markers = array_merge($markers, $this->getMarkers($item));
+                      
+                		$this->renderMarkers = array_unique($markers);
+                
 
 
 
 				// build query for display:
@@ -807,10 +825,13 @@
 
 if ($this->debugTimes) {  $this->getParsetime(__METHOD__); }
 
-				$markerArray['###NEWS_CATEGORY_ROOTLINE###'] = '';
-				if($this->conf['catRootline.']['showCatRootline'] && $this->piVars['cat'] && !strpos($this->piVars['cat'],',')) {
-					$markerArray['###NEWS_CATEGORY_ROOTLINE###'] = $this->getCategoryPath(array(array('catid' => intval($this->piVars['cat']))));
-				}
+                if($this->isRenderMarker('###NEWS_CATEGORY_ROOTLINE###'))
+                {
+				    $markerArray['###NEWS_CATEGORY_ROOTLINE###'] = '';
+				    if($this->conf['catRootline.']['showCatRootline'] && $this->piVars['cat'] && !strpos($this->piVars['cat'],',')) {
+					    $markerArray['###NEWS_CATEGORY_ROOTLINE###'] = $this->getCategoryPath(array(array('catid' => intval($this->piVars['cat']))));
+				    }
+                }
 
 				if ($theCode == 'XML') {
 					$markerArray = $this->getXmlHeader();
@@ -848,7 +869,7 @@
 					} else {
 
 						$this->pi_alwaysPrev = $pbConf['alwaysPrev'];
-						if ($this->conf['usePiBasePagebrowser']) {
+						if ($this->conf['usePiBasePagebrowser'] && $this->isRenderMarker('###BROWSE_LINKS###')) {
 							$this->internal['pagefloat'] = $pbConf['pagefloat'];
 							$this->internal['showFirstLast'] = $pbConf['showFirstLast'];
 							$this->internal['showRange'] = $pbConf['showRange'];
@@ -936,6 +957,9 @@
 				// Init Templateparts: $t['total'] is complete template subpart (TEMPLATE_LATEST f.e.)
 				$t = array();
 				$t['total'] = $this->getNewsSubpart($this->templateCode, $this->spMarker('###' . $templateName . '###'));
+                $markers = $this->getMarkers($t['total']);
+                $this->renderMarkers = array_unique($markers);
+
 				// Reset:
 				$subpartArray = array();
 				$wrappedSubpartArray = array();
@@ -1060,7 +1084,8 @@
 				$this->config['catOrderBy'] = $this->conf[$prefix_display.'.']['catOrderBy'];
 			}
 
-			$this->categories[$row['uid']] = $this->getCategories($row['uid']);
+            if($this->isRenderMarker('###NEWS_CATEGORY_ROOTLINE###'))
+			    $this->categories[$row['uid']] = $this->getCategories($row['uid'], FALSE, $row['uid_foreign']);
 
 			if ($row['type'] == 1 || $row['type'] == 2) {
 				// News type article or external url
@@ -1187,6 +1225,8 @@
 			if (!$item) {
 				$item = $this->getNewsSubpart($this->templateCode, $this->spMarker('###TEMPLATE_'.$this->theCode.'###'), $row);
 			}
+            $markers = $this->getMarkers($item);
+            $this->renderMarkers = array_unique($markers);            
 				// reset marker array
 			$wrappedSubpartArray = array();
 				// build the backToList link
@@ -1317,6 +1357,11 @@
 			// get template subpart
 			$t['total'] = $this->getNewsSubpart($this->templateCode, $this->spMarker('###TEMPLATE_ARCHIVE###'));
 			$t['item'] = $this->getLayouts($t['total'], $this->alternatingLayouts, 'MENUITEM');
+            $markers = $this->getMarkers($t['total']);
+            foreach($t['item'] as $item)
+                $markers = array_merge($markers, $this->getMarkers($item));
+                  
+            $this->renderMarkers = array_unique($markers);            
 			$tCount = count($t['item']);
 			$cc = 0;
 
@@ -1640,13 +1685,13 @@
 
 		// get image markers
 		$markerArray['###NEWS_IMAGE###'] = '';
-		if ($this->isRenderField('image')) {
+		if ($this->isRenderField('image') && $this->isRenderMarker('###NEWS_IMAGE###')) {
 			$markerArray = $this->getImageMarkers($markerArray, $row, $lConf, $textRenderObj);
 		}
 
 		$markerArray['###NEXT_ARTICLE###'] = '';
 		$markerArray['###PREV_ARTICLE###'] = '';
-		if ($textRenderObj == 'displaySingle') {
+		if ($textRenderObj == 'displaySingle' && ($this->isRenderMarker('###NEXT_ARTICLE###') || $this->isRenderMarker('###PREV_ARTICLE###'))) {
 			$markerArray = $this->getPrevNextLinkMarkers($row, $lConf, $markerArray);
 		}
 
@@ -1661,7 +1706,7 @@
 		$markerArray['###CATWRAP_B###'] = '';
 		$markerArray['###CATWRAP_E###'] = '';
 		$markerArray['###NEWS_CATEGORY_ROOTLINE###'] = '';
-		if ($this->isRenderField('category')) {
+		if ($this->isRenderField('category') && $this->isRenderMarker('###NEWS_CATEGORY_ROOTLINE###')) {
 			// find categories for the current record
 			$this->categories = array();
 			$this->categories[$row['uid']] = $this->getCategories($row['uid']);
@@ -1737,7 +1782,7 @@
 				), '');
 			}
 		}
-		if ($this->isRenderField('bodytext')) {
+		if ($this->isRenderField('bodytext') && $this->isRenderMarker('###NEWS_CONTENT###')) {
 			if ($textRenderObj == 'displaySingle' && !$row['no_auto_pb'] && $this->config['maxWordsInSingleView']>1) {
 				$row['bodytext'] = $this->insertPagebreaks($row['bodytext'],count(t3lib_div::trimExplode(' ',$row['short'],1)));
 			}
@@ -1785,7 +1830,7 @@
 		// get related news
 		$markerArray['###TEXT_RELATED###'] = '';
 		$markerArray['###NEWS_RELATED###'] = '';
-		if ($this->isRenderField('related')) {
+		if ($this->isRenderField('related') && ($this->isRenderMarker('###TEXT_RELATED###') || $this->isRenderMarker('###NEWS_RELATED###'))) {
 			$relatedNews = $this->getRelated($row['uid']);
 			if ($relatedNews) {
 				$rel_stdWrap = t3lib_div::trimExplode('|', $this->conf['related_stdWrap.']['wrap']);
@@ -1802,7 +1847,7 @@
 		$markerArray['###TEXT_LINKS###'] = '';
 		$markerArray['###NEWS_LINKS###'] = '';
 		$links = trim($row['links']);
-		if ($links && $this->isRenderField('links')) {
+		if ($links && $this->isRenderField('links') && ($this->isRenderMarker('###TEXT_LINKS###') || $this->isRenderMarker('###NEWS_LINKS###'))) {
 			$links_stdWrap = t3lib_div::trimExplode('|', $lConf['links_stdWrap.']['wrap']);
 			$newsLinks = $this->local_cObj->stdWrap($this->formatStr($row['links']), $lConf['linksItem_stdWrap.']);
 			$markerArray['###TEXT_LINKS###'] = $links_stdWrap[0].$this->local_cObj->stdWrap($this->pi_getLL('textLinks'), $lConf['linksHeader_stdWrap.']);
@@ -1815,7 +1860,7 @@
 		$markerArray['###TEXT_FILES###'] = '';
 		$markerArray['###FILE_LINK###'] = '';
 		$markerArray['###NEWS_RSS2_ENCLOSURES###'] = '';
-		if ($row['news_files'] && ($this->isRenderField('news_files') || $this->theCode == 'XML')) {
+		if ($row['news_files'] && ($this->isRenderField('news_files') && ($this->isRenderMarker('###TEXT_FILES###') || $this->isRenderMarker('###FILE_LINK###')) || $this->theCode == 'XML')) {
 			$files_stdWrap = t3lib_div::trimExplode('|', $this->conf['newsFiles_stdWrap.']['wrap']);
 			$markerArray['###TEXT_FILES###'] = $files_stdWrap[0].$this->local_cObj->stdWrap($this->pi_getLL('textFiles'), $this->conf['newsFilesHeader_stdWrap.']);
 			$fileArr = explode(',', $row['news_files']);
@@ -3979,6 +4034,19 @@
 	function getNewsSubpart($myTemplate, $myKey, $row = Array()) {
 		return ($this->cObj->getSubpart($myTemplate, $myKey));
 	}
+    
+    /**
+     * [Describe function...]
+     *
+     * @param    [type]        $fieldName: ...
+     * @return    [type]        ...
+     */
+    function isRenderMarker($marker) {
+        if (in_array($marker, $this->renderMarkers))
+            return true;
+            
+        return false;
+    }    
 
 	/**
 	 * [Describe function...]
@@ -3993,6 +4061,8 @@
 		if (t3lib_div::inList($this->renderFields[$this->theCode],$fieldName)) {
 			return true;
 		}
+        // TEMP FIX:
+        return true;
 	}
 
 
@@ -4380,15 +4450,25 @@
 			debug($msg, $lbl, $code_line, $msg['file:'], 3);
 		}
 	}
+    
+    /**
+     * [Describe function...]
+     *
+     * @param    [type]        $template: ...
+     * @return    [type]        ...
+     */
+    function getMarkers($template)
+    {
+        preg_match_all('/###(.+)###/Us', $template, $matches);
+        return $matches[0];
+    }
 
 
 
 
-
-
 }
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tt_news/pi/class.tx_ttnews.php']) {
 	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/tt_news/pi/class.tx_ttnews.php']);
 }
-?>
\ No newline at end of file
+?>
