Project

General

Profile

Actions

Feature #24905

closed

Add LOOP cObject

Added by Xavier Perseguers almost 14 years ago. Updated almost 10 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2011-01-31
Due date:
% Done:

0%

Estimated time:
PHP Version:
5.2
Tags:
Complexity:
Sprint Focus:

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

17420.diff (5.62 KB) 17420.diff Administrator Admin, 2011-01-31 14:08
17420_v2.diff (5.69 KB) 17420_v2.diff Administrator Admin, 2011-01-31 15:47
Actions #1

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.

Actions #2

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
}
}
}
Actions #3

Updated by Mathias Schreiber almost 10 years ago

  • Description updated (diff)
  • Status changed from New to Closed
  • Target version deleted (0)

use Fluid please :)

Actions

Also available in: Atom PDF