database-query data processor
The
\TYPO3\,
alias database-, fetches records from the database, using
standard TypoScript select semantics. The result is then passed to the
FLUIDTEMPLATE as an array.
This way a FLUIDTEMPLATE cObject can iterate over the array of records.
The
database- processor can be used in combination with the
record-transformation data processor to use additional computed information.
Table of contents
Options:
| Name | Type | Default |
|---|---|---|
| if condition | '' | |
| string / stdWrap | '' | |
| string / stdWrap | 'records' | |
| array of Data processors | [] |
-
- Type
- if condition
- Default
- ''
Only if the condition is met the data processor is executed.
-
- Type
- array of Data processors
- Default
- []
Array of data processors to be applied to all fetched records.
Note
All other options will be interpreted as in the TypoScript function
select
, including
pid,
order,
where
, etc. See the reference of
select.
Warning
When using the DatabaseQueryProcessor, you may encounter issues with language and/or versioning overlays, that currently can not be resolved. See here for more information.
Example: Usage in combination with the RecordTransformationProcessor
Example usage for the data processor in conjunction with the record-transformation data processor.
page = PAGE
page {
10 = PAGEVIEW
10 {
paths.10 = EXT:my_extension/Resources/Private/Templates/
dataProcessing {
10 = database-query
10 {
as = categories
table = sys_category
where = parent=0
dataProcessing.10 = record-transformation
}
}
}
}
For usage of the variables within Fluid see Example: Usage with FLUIDTEMPLATE.
Example: Display speaker records
Please see also About the examples.
In this example, an extension stores the speakers of a conference in the
table tx_, with the fields name, company, bio, and
photo. A content element lists the speakers from the folder in its field
pages.
We define the
data property to use the
Database:
lib.contentElement.templateRootPaths.20 = EXT:my_extension/Resources/Private/Templates/ContentElements/
tt_content {
myextension_speakers =< lib.contentElement
myextension_speakers {
templateName = Speakers
dataProcessing.10 = database-query
dataProcessing.10 {
if.isTrue.field = pages
table = tx_myextension_speaker
pidInList.field = pages
orderBy = name
as = speakers
# Fetches the photo of each speaker
dataProcessing {
10 = files
10 {
references.fieldName = photo
}
}
}
}
}
In the Fluid template, iterate over the records. As the files data processor processes the photo of each record, the template can output the photos as well.
<html data-namespace-typo3-fluid="true" xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers">
<h2>Data in variable speakers</h2>
<f:debug inline="true">{speakers}</f:debug>
<h2>Output</h2>
<div class="row">
<f:for each="{speakers}" as="speaker">
<div class="col-12 col-md-4">
<div class="card">
<f:if condition="{speaker.files.0}">
<f:image image="{speaker.files.0}" class="card-img-top h-auto" width="400"/>
</f:if>
<div class="card-body">
<h5 class="card-title">{speaker.data.name}</h5>
<h6 class="card-subtitle text-body-secondary">{speaker.data.company}</h6>
<div class="card-text"><f:format.html>{speaker.data.bio}</f:format.html></div>
</div>
</div>
</div>
</f:for>
</div>
</html>
Each entry of the records array contains the data of the table in data
and the data of the photo in files.
Example: Display sorted records from an MM table working with workspaces
Please see also About the examples.
We define the
data property to use the
Database. To make
use of the sorting field in the MM table, a join is required.
However, performing this join will cause the fields from the MM table to be selected in the query. This can break the output when previewing the page using workspaces.
To prevent this issue, we use the
select property to explicitly define which fields should be retrieved.
tt_content.myextension_mycontentelement =< lib.contentElement
tt_content.myextension_mycontentelement {
templateName = MyContentElement
templateRootPaths {
102 = EXT:my_extension/Resources/Private/Templates/
}
partialRootPaths {
102 = EXT:my_extension/Resources/Private/Partials/
}
layoutRootPaths {
102 = EXT:my_extension/Resources/Private/Layouts/
}
dataProcessing {
10 = database-query
10 {
table = tx_myextension_myrecord
pidInList.data = site:rootPageId
selectFields = tx_myextension_myrecord.*
join = tx_myextension_myrecord_mm mm ON mm.uid_foreign = tx_myextension_myrecord.uid
where.data = field:uid
where.intval = 1
where.wrap = mm.uid_local=|
orderBy = mm.sorting
as = myrecord
# resolving the image reference
dataProcessing {
10 = TYPO3\CMS\Frontend\DataProcessing\FilesProcessor
10 {
references.fieldName = image
as = images
}
}
}
}
}