[TYPO3-dev] CONTENT: add support for virtual table
Xavier Perseguers
typo3 at perseguers.ch
Thu Oct 21 13:30:22 CEST 2010
Hi,
This morning I thought about something that is not (yet) possible in TS:
do a "foreach" on virtual records, that is an array of arbitrary data.
Background: in an extension, you may easily allow arbitrary data to be
processed by TS with:
$rows = array(
array('id' => 1, 'name' => 'foo'),
array('id' => 3, 'name' => 'foobar'),
array('id' => 4, 'name' => 'foobarbar'),
);
$contentObj = t3lib_div::makeInstance('tslib_cObj');
$contentObj->start($data);
$content = '';
foreach ($rows as $row) {
$content .= $contentObj->cObjGetSingle($conf['myRow'], $conf['myRow.']);
}
return $content;
and then let TypoScript be used to process it. E.g.,
plugin.myext_pi1 {
myRow = TEXT
myRow.field = name
}
However there is no way to perform the foreach in pure TS. It would be
useful for instance if a userfunc could return a plain PHP array as
variable $rows above:
class user_myext {
public function getTestData($content, array $config) {
return array(
array('id' => 1, 'name' => 'foo'),
array('id' => 3, 'name' => 'foobar'),
array('id' => 4, 'name' => 'foobarbar'),
);
}
}
Attached patch allows this:
page = PAGE
page.10 = CONTENT
page.10.wrap = <ul> | </ul>
page.10 {
table = virtual
data = USER
data.userFunc = user_myext->getTestData
renderObj = COA
renderObj {
10 = TEXT
10.field = id
10.noTrimWrap = ||: |
20 = TEXT
20.field = name
wrap = <li> | </li>
}
}
and this will generate (prettified):
<ul>
<li>1: foo</li>
<li>3: foobar</li>
<li>4: foobarbar</li>
</ul>
First chunk in the diff file is to allow USER/USER_INT to return an
array without casting it to string.
This is not ready for Core, but I'd like to get your feeling/feedback to
improve it.
Cheers
Xavier
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CONTENT_virtual.diff
URL: <http://lists.typo3.org/pipermail/typo3-dev/attachments/20101021/23902657/attachment.asc>
More information about the TYPO3-dev
mailing list