process-each
Class:
\CPSIT\
Iterates over an array (or other iterable) and, for each item, evaluates a
variables
configuration block and/or runs a nested
data chain against that single item. This is the
usual way to enrich or reshape every entry of an array produced by an
earlier processor — for example, running
object-
against each file reference returned by TYPO3's core
files
processor.
Resolving the items to iterate
The value to iterate over is resolved in the following order:
data, if configured (see Referencing data).Source - Otherwise, an inline
dataarray configured directly on this processor. - Otherwise, a
datakey already present inprocessed. This makesData process-usable as a nested processor inside TYPO3's core processors such aseach database-orquery menu— which expose each record asdatato their nesteddatachain — without having to repeatProcessing dataexplicitly.Source
If none of these yield an iterable value, the processed data is returned unchanged.
Usage
tt_content.textpic = HANDLEBARSTEMPLATE
tt_content.textpic {
templateName = @textpic
dataProcessing {
10 = files
10 {
references.fieldName = image
as = files
}
20 = process-each
20 {
dataSource = processedData:files
as = processedFiles
dataProcessing {
10 = object-access
10 {
object.current = 1
path = publicUrl
as = url
}
20 = object-access
20 {
object.current = 1
path = fileType
as = type
}
}
}
}
}
Each file reference resolved by the core
files
processor is
set as the content object's current value while the nested
data chain runs, so
object- can
pull individual properties off it with
object.
(see Using the current value). Since file references cannot be
converted to strings, they are wrapped before being set as current value (see
Wrapped current values). The per-item results are collected
under
processed (keyed by the original array keys).
Per-item processing
Two mechanisms are available for each item, and can be combined:
variables-
A
variablesblock, processed exactly like the top-levelvariablesofHANDLEBARSTEMPLATE, but with the content object's current value set to the item. Usecurrent = 1(instead offield) to reference the item itself:20 = process-each 20 { dataSource = processedData:tags as = processedTags variables { label = TEXT label.current = 1 label.case = upper } }Copied!dataandcurrentare reserved and cannot be used as variable names here. dataProcessing - A standard nested
datachain (see Usage), with the item set as current value. Its result is merged with — and overrides — whateverProcessing variablesproduced for the same item.
Properties
data- Inline data to iterate over, used if
datais not configured (see Resolving the items to iterate).Source dataSource - Data source(s) to read the iterable from (see
Resolving the items to iterate).
datauses the content object's current value instead (see Using the current value).Source. current as- Target key in the processed data array the resulting (keyed) array is
stored under. Default:
result. variables- Per-item variables block (see Per-item processing).
dataProcessing - Per-item nested data processors (see Per-item processing).