[TYPO3-dev] CONTENT: add support for virtual table

Ernesto Baschny [cron IT] ernst at cron-it.de
Thu Oct 21 13:56:02 CEST 2010


Hi Xavier,

nice suggestion!

We have had some discussions during our Code Sprint about TypoScript in
general and one topic that popped up was general support for "arrays" in
TypoScript and flexible ways of iterate over them (e.g. FOREACH) and
manipulate them (e.g. arrayShift, arraySlice, etc).

Your approach seems to use the existing "sql" functionality and just
allow PHP to return an array on its own, which is also quite interesting.

Maybe we can find a generic way of supporting arrays in TypoScript,
which could also handle your use-case?

Cheers,
Ernesto

Xavier Perseguers schrieb am 21.10.2010 13:30:
> 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





More information about the TYPO3-dev mailing list