media
Class:
\CPSIT\
Resolves a file or file reference and runs it through a matching media processor — a pluggable component that turns a resource into whatever shape a template needs (for example, an image with responsive source sets). The extension ships with a single built-in media processor for images; see MediaProcessor for how to register your own.
Data sources
file
references the file or file reference to process, e.g.
the first file resolved by TYPO3's
files
processor
(
processed). See Referencing data
for the syntax.
Usage
tt_content.textpic = HANDLEBARSTEMPLATE
tt_content.textpic {
templateName = @textpic
dataProcessing {
10 = files
10 {
references.fieldName = image
as = files
}
20 = media
20 {
file = processedData:files/0
as = image
config {
image {
sourceSets {
small {
maxW = 600c
}
}
}
}
}
}
}
The first file resolved by the core
files
processor is passed
to
media
, which picks the matching media processor — here,
the built-in
image
processor — and stores its result under
image
.
Tip
To process all files instead of only the first one, nest
media
inside a process-each processor
and use
file. to reference the file currently
being processed:
20 = process-each
20 {
dataSource = processedData:files
as = images
dataProcessing {
10 = media
10 {
file.current = 1
config {
image {
sourceSets {
small {
maxW = 600c
}
}
}
}
}
}
}
Since
as
is omitted on
media
, the result is
merged into each item. The template can then iterate over all images:
{{#each images}}
<img src="{{sourceSets.small.src}}" alt="">
{{/each}}
Properties
file- Data source reference the resource is read from (see Data sources). Required.
as- Target key in the processed data array the media processor's result is stored under. Optional — if omitted, the result is merged recursively into the processed data instead.
config.<name>- Configuration passed to the media processor registered under
<name>(e.g.config.for the built-in image processor). Only applied if that processor actually matches the resolved resource.image
If
file
cannot be resolved, or no registered media processor
supports the resolved resource, a warning is logged and the processed data
is returned unchanged.
Built-in media processor: image
The built-in image processor matches any resource that is an image. It
generates one processed image per configured source set, using
Content under the hood, so each
source set accepts the same configuration as TYPO3's core imgResource
function (e.g.
max,
max,
width
,
height
).
Its configuration is nested under
config. (see
Properties below) and results in the
following shape:
sourceSets - A map of the configured source set names to their processed image data
(
src,width,height). originalFile - The resolved, unprocessed file (
\TYPO3\).CMS\ Core\ Resource\ Abstract File