Feature #24905
closedAdd LOOP cObject
0%
Description
TYPO3 is missing a content object to loop over arrays and collections.
See related discussion in dev list:
Title: "Possible RFC : Introducing ARRAY_LOOP cObject"
Thread: http://typo3.toaster-schwerin.de/typo3_dev/2011_01/msg00168.html
(issue imported from #M17420)
Files
Updated by Xavier Perseguers almost 14 years ago
Note: if you have some collection that implements Iterator interface, you should transform it into an array:
iterator_to_array($yourIterator, TRUE)
in order for tslib_content to work happily with it.
Updated by Xavier Perseguers almost 14 years ago
Example of use:
in pi1/class.tx_yourext_pi1.php, method main():
$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['persons'],
$this->conf['persons.']
);
in res/template.html:
<html>
<head>
<title></title>
</head>
<body>
<table>
<thead>
<tr>
<th>###HEADER_FIRSTNAME###</th>
<th>###HEADER_LASTNAME###</th>
</tr>
</thead>
<tbody>
<tr>
<td>###FIRSTNAME###</td>
<td>###LASTNAME###</td>
</tr>
</tbody>
</table>
</body>
</html>
TypoScript:
plugin.tx_yourext_pi1.persons = TEMPLATE
plugin.tx_yourext_pi1.persons {
template = FILE
template.file = EXT:your_ext/res/template.html
workOnSubpart = PERSONS
marks {
HEADER_FIRSTNAME = TEXT
HEADER_FIRSTNAME.value = First Name
HEADER_LASTNAME = TEXT
HEADER_LASTNAME.value = Last Name
}
subparts.PERSON = LOOP
subparts.PERSON.renderObj = TEMPLATE
subparts.PERSON.renderObj.template < .template
subparts.PERSON.renderObj {
workOnSubpart = PERSON
marks {
FIRSTNAME = TEXT
FIRSTNAME.field = firstname
LASTNAME = TEXT
LASTNAME.field = lastname
}
}
}
Updated by Mathias Schreiber almost 10 years ago
- Description updated (diff)
- Status changed from New to Closed
- Target version deleted (
0)
use Fluid please :)