[TYPO3-dev] Possible RFC : Introducing ARRAY_LOOP cObject

Xavier Perseguers typo3 at perseguers.ch
Mon Jan 31 11:38:05 CET 2011


Hi,

This was discussed at T3DD10. I often have to deal with external data 
which basically is an array of data just as what is returned by 
$GLOBALS['TYPO3_DB']->exec_SELECTgetRows() or an array of some domain 
object, when programming the Extbase way.

The problem is that there is no way to loop over such an array with pure 
TypoScript.

Please find enclosed a possible patch to do that.

How to use it:

in your pibase extension, use following code:

// $myData = some-code-returning-an-array-of-data
$myData = array();
$myData[] = array('lastname' => 'Hader', 'firstname' => 'Oliver');
$myData[] = array('lastname' => 'Kamper', 'firstname' => 'Steffen');
$myData[] = array('lastname' => 'Baschny', 'firstname' => 'Ernesto');
$myData[] = array('lastname' => 'Perseguers', 'firstname' => 'Xavier');

$this->cObj->start($myData);
return $this->cObj->cObjGetSingle(
	$this->conf['dataLoop'],
	$this->conf['dataLoop.']
);

and in your TypoScript:

plugin.tx_myext_pi1 {
	dataLoop = ARRAY_LOOP
	dataLoop {
		wrap = <table>|</table>

		renderObj = TEXT
		renderObj.field = lastname
		renderObj.wrap = <tr><td>|</td></tr>
	}
}

The modification I did on FLUIDTEMPLATE allows this if you have an array 
of some domain object:

plugin.tx_myext_pi1 {
	dataLoop = ARRAY_LOOP
	dataLoop.renderObj = FLUIDTEMPLATE
	dataLoop.renderObj... // as usual
}

and you'll get your single object into {data}

Perhaps you have other possible enhancements but we really should have 
such a content object as it allows full control on how data is processed.

Just as a side note, thanks to FLUIDTEMPLATE, it's already possible to 
loop over an array of domain objects using same code as above if one 
writes this:

plugin.tx_myext_pi1 {
	dataLoop = FLUIDTEMPLATE
	dataLoop... // as usual
}

and

<f:for each="{data}" as="person">

</f:for>

in the template but it still is not fine enough when you don't want to 
modify the template but would like to apply some transformations on 
single object rendering using pure TypoScript.

Cheers
Xavier


More information about the TYPO3-dev mailing list