--- C:/Users/fr/Desktop/class.tx_templavoila_pi1_org.php	Wed Oct 06 15:16:23 2010
+++ C:/Users/fr/Desktop/class.tx_templavoila_pi1.php	Thu Oct 07 11:51:49 2010
@@ -348,6 +349,22 @@
 						if ($GLOBALS['TT']->LR) $GLOBALS['TT']->push('Processing data');
 							$vKey = ($GLOBALS['TSFE']->sys_language_isocode && !$langDisabled && $langChildren) ? 'v'.$GLOBALS['TSFE']->sys_language_isocode : 'vDEF';
 
+							$element_tree=$GLOBALS['TSFE']->register['tx_templavoila_pi1.element_tree'];
+							foreach($data['data'][$sheet][$lKey] as $field => $childs){
+								$uids=t3lib_div::trimExplode(',', $childs[$vKey]);
+								foreach($uids as $uid){
+									$element_tree[$row['uid']]['elements'][$field][$uid]=array();
+								}
+							}
+							foreach($element_tree as $euid=>$elements){
+								foreach($elements['elements'] as $element=>$uids){
+									if (isset($element_tree[$euid]['elements'][$element][$row['uid']])){
+										$element_tree[$row['uid']]['parent']=array('uid'=>$euid, 'element'=>$element);
+									}
+								}
+							}
+							$GLOBALS['TSFE']->register['tx_templavoila_pi1.element_tree']=$element_tree;
+
 								/* Hook to modify value key - e.g. used for EXT:languagevisibility */
 							foreach($hookObjectsArr as $hookObj)	{
 								if (method_exists ($hookObj, 'renderElement_preProcessValueKey')) {
@@ -358,7 +375,7 @@
 							$TOlocalProc = $singleSheet ? $TOproc['ROOT']['el'] : $TOproc['sheets'][$sheet]['ROOT']['el'];
 								// Store the original data values before the get processed.
 							$originalDataValues = $dataValues;
-							$this->processDataValues($dataValues,$dataStruct['ROOT']['el'],$TOlocalProc,$vKey);
+							$this->processDataValues($dataValues,$dataStruct['ROOT']['el'],$TOlocalProc,$vKey,$row['uid'],$element_tree);
 
 								// Hook: renderElement_postProcessDataValues
 							foreach ($hookObjectsArr as $hookObj) {
@@ -431,7 +448,7 @@
 	 * @param	string		Value key
 	 * @return	void
 	 */
-	function processDataValues(&$dataValues,$DSelements,$TOelements,$valueKey='vDEF')	{
+	function processDataValues(&$dataValues,$DSelements,$TOelements,$valueKey='vDEF',$uid=0, $element_tree=array())	{
 		if (is_array($DSelements) && is_array($dataValues))	{
 
 				// Create local processing information array:
@@ -500,17 +517,20 @@
                 }
             }
 
+			if (isset($element_tree[$uid])){
+				$nesting=array();
+				$tmp_cur=$element_tree[$uid];
+				while(isset($tmp_cur['parent'])){
+					$nesting[]=$tmp_cur['parent']['element'];
+					$tmp_cur=$element_tree[$tmp_cur['parent']['uid']];
+				}
+				$nesting=array_reverse($nesting);
+			}
 				// For each DS element:
 			foreach($DSelements as $key => $dsConf)	{
 					// Store key of DS element and the parents being handled in global register
-				$nestedFields = '';
-				if (isset($GLOBALS['TSFE']->register['tx_templavoila_pi1.current_field'])) {
-					 $nestedFields = implode(',', array($GLOBALS['TSFE']->register['tx_templavoila_pi1.current_field'], $key));
-				} else {
-					$nestedFields = $key;
-				}
-				$GLOBALS['TSFE']->register['tx_templavoila_pi1.nested_fields'] = $nestedFields;
 				$GLOBALS['TSFE']->register['tx_templavoila_pi1.current_field'] = $key;
+				$GLOBALS['TSFE']->register['tx_templavoila_pi1.nested_fields'] = implode(',', array_merge($nesting, array($key)));
 
 						// Array/Section:
 				if ($DSelements[$key]['type']=='array')	{
@@ -533,7 +553,7 @@
 								if (is_array($el))	{
 									$theKey = key($el);
 									if (is_array($dataValues[$key]['el'][$ik][$theKey]['el']))	{
-										$this->processDataValues($dataValues[$key]['el'][$ik][$theKey]['el'],$DSelements[$key]['el'][$theKey]['el'],$TOelements[$key]['el'][$theKey]['el'],$valueKey);
+										$this->processDataValues($dataValues[$key]['el'][$ik][$theKey]['el'],$DSelements[$key]['el'][$theKey]['el'],$TOelements[$key]['el'][$theKey]['el'],$valueKey,$uid,$element_tree);
 
 											// If what was an array is returned as a non-array (eg. string "__REMOVE") then unset the whole thing:
 										if (!is_array($dataValues[$key]['el'][$ik][$theKey]['el']))	{
@@ -543,7 +563,7 @@
 								}
 							}
 						} else {
-							$this->processDataValues($dataValues[$key]['el'],$DSelements[$key]['el'],$TOelements[$key]['el'],$valueKey);
+							$this->processDataValues($dataValues[$key]['el'],$DSelements[$key]['el'],$TOelements[$key]['el'],$valueKey,$uid,$element_tree);
 						}
 					}
 				} else {
