diff -ru typo3_src-4.3.2.orig/t3lib/class.t3lib_tstemplate.php typo3_src-4.3.2/t3lib/class.t3lib_tstemplate.php --- typo3_src-4.3.2.orig/t3lib/class.t3lib_tstemplate.php 2010-02-23 12:00:03.000000000 +0100 +++ typo3_src-4.3.2/t3lib/class.t3lib_tstemplate.php 2010-02-26 10:06:20.000000000 +0100 @@ -572,17 +572,22 @@ } } else { // NORMAL OPERATION: $basedOnArr = t3lib_div::intExplode(',', $row['basedOn']); - foreach ($basedOnArr as $id) { // traversing list - if (!t3lib_div::inList($idList,'sys_'.$id)) { // if $id is not allready included ... - $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid='.intval($id).' '.$this->whereClause); - if ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // there was a template, then we fetch that - $this->versionOL($subrow); - if (is_array($subrow)) { - $this->processTemplate($subrow,$idList.',sys_'.$id,$pid, 'sys_'.$id,$templateID); - } - } - $GLOBALS['TYPO3_DB']->sql_free_result($res); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_template', 'uid in (' . $row['basedOn'] . ') ' . $this->whereClause); + $subrows = array(); + while ($subrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { + // makes it easier to access the rows later + $subrows[$subrow['uid']] = $subrow; + } + $GLOBALS['TYPO3_DB']->sql_free_result($res); + // traversing list to ensure sorting of the templates + foreach ($basedOnArr as $id) { + if (t3lib_div::inList($idList,'sys_' . $id)) { + continue; //skip template if already included } + $this->versionOL($subrow); + if (is_array($subrows[$id])) { + $this->processTemplate($subrows[$id],$idList . ',sys_' . $id,$pid, 'sys_' . $id,$templateID); + } } } }