iterable-to-array
Class:
\CPSIT\
Converts an iterable value — an Extbase
Query as
returned by a repository, an
Object, a plain
Iterator
,
or a
Generator
— into a plain array. Templates and other data
processors generally expect array data, so this processor is the usual
bridge between a repository result and the rest of the
data chain.
Data sources
The
iterable
property does not name the source value directly.
Instead, it names the key under which the value is stored, and that key is
looked up across all four data sources, tried in the order listed:
| Data source identifier | Contains |
|---|---|
processor | This processor's own config block |
processed | Accumulated output from previous processors |
content | Current record's field values |
content | Top-level
HANDLEBARSTEMPLATE
config |
This is what allows
iterable
to refer to a value placed into
processed by a preceding processor's
as
option, or to a variable an Extbase controller assigned directly to the view.
Usage
final class NewsController extends HandlebarsController
{
public function listAction(): ResponseInterface
{
$this->view->assign('news', $this->newsRepository->findAll());
return $this->htmlResponse($this->renderView());
}
}
plugin.tx_myextension_news.handlebars {
News::list {
dataProcessing {
10 = iterable-to-array
10 {
iterable = news
as = newsItems
}
}
}
}
Processing individual items
Each converted item is wrapped as
data
and run through a
nested
data chain, just like TYPO3's own
database- processor does for its records. This only
happens when a nested chain is actually configured, so plain conversions are
left untouched:
dataProcessing {
10 = iterable-to-array
10 {
iterable = news
as = newsItems
dataProcessing {
10 = object-access
10 {
object = data
path = title
as = title
}
}
}
}
Properties
iterable- Key under which the source value is looked up (see Data sources). Required.
as- Target key in the processed data array the resulting array is stored
under. Default:
result. preserveKeys - Boolean. When
1, the original keys of the iterable (e.g. array keys orGeneratorkeys) are preserved. When0, the result is reindexed as a plain list. Default:0. dataProcessing - Nested data processors, run for each item of the converted array (see Processing individual items).
If
iterable
is not configured, or the resolved value is not
iterable, a warning is logged and the processed data is returned unchanged.