HANDLEBARSTEMPLATE content object
HANDLEBARSTEMPLATE
is a custom content object type provided by
this extension. It compiles and renders a Handlebars template, resolving
template paths, processing variables, and registering assets — all from
TypoScript configuration.
The content object tries to follow the implementation details of TYPO3's
FLUIDTEMPLATE content object as closely
as possible. Properties such as
template,
template,
variables
,
settings
and
data work the same way,
including the reserved
data
and
current
variables. Existing
FLUIDTEMPLATE
configuration can therefore
be reused in most cases. The main difference is that there are no
layout, since Handlebars layouts are
resolved as partials.
tt_content.header = HANDLEBARSTEMPLATE
tt_content.header {
templateName = Header
templateRootPaths.20 = EXT:my_extension/Resources/Private/Templates
}
Properties
templateName
- Type
- string / stdWrap
- Description
- Name of the template to render. The value is resolved as a filename
(without the
.hbsextension) relative to the configured template root paths. Prefix the name with@to look up the file by its bare filename, see Referencing templates and partials. Exactly one oftemplate,Name template, orfilemust be set. - Example
templateName = Header # Flat name templateName = @header # With stdWrap templateName.field = tx_myext_template_nameCopied!
format
- Type
- string / stdWrap
- Description
- File extension of the template file. If not set, the file extensions
hbs,handlebarsandhtmlare tried in this order. Setting a format restricts the lookup to this file extension. It must be one of the supported file extensions. - Example
format = handlebarsCopied!
template
- Type
- string / stdWrap
- Description
- Inline Handlebars source used directly as the template. Useful for short
or dynamically constructed templates. Cannot be used together with
templateorName file. - Example
template = <h1>{{header}}</h1>Copied!
file
- Type
- string / stdWrap
- Description
- Absolute or
EXT:-relative path to a Handlebars template file. Cannot be used together withtemplateorName template. - Example
file = EXT:my_extension/Resources/Private/Templates/Special.hbsCopied!
templateRootPaths
- Type
- array (numeric keys)
- Description
- Template root paths for this content object. These are added to the content object path provider with the highest priority (100), overriding any TypoScript or service container paths for this rendering. Higher numeric keys take precedence over lower ones.
- Example
templateRootPaths { 10 = EXT:my_extension/Resources/Private/Templates 20 = EXT:my_other_extension/Resources/Private/Templates }Copied!
Note
The shorthand
template (singular) sets a single
path at key 0.
partialRootPaths
- Type
- array (numeric keys)
- Description
- Partial root paths for this content object. Same priority and override
rules as
template.Root Paths - Example
partialRootPaths { 10 = EXT:my_extension/Resources/Private/Partials }Copied!
Note
The shorthand
partial (singular) sets a single
path at key 0.
variables
- Type
- array
- Description
-
Variables passed to the template. Each entry is processed as a content object against the current content element's data record. Simple string values are passed through as-is; entries with a sub-array are rendered via
Content.Object Renderer:: c Obj Get Single () Two variable names are reserved and always available automatically:
data— the full content element data arraycurrent— the current field value
- Example
variables { header = TEXT header.field = header bodytext = TEXT bodytext.field = bodytext bodytext.parseFunc =< lib.parseFunc_RTE image = FILES image.references.fieldName = image # Simple variable (no content object rendering) wrapperClass = container }Copied!
settings
- Type
- array
- Description
- Arbitrary key-value pairs passed to the template as the
settingsvariable. Unlikevariables, entries are not processed as content objects — values are used as plain strings. - Example
settings { showDate = 1 }Copied!In the template:
{{#if settings.showDate}} <time>{{date}}</time> {{/if}}Copied!
dataProcessing
- Type
- array
- Description
-
Standard data processors, executed after
variablesare resolved. Processors receive and return the$processedarray. Any key added by a processor is available as a template variable.Data The extension provides additional processors, e.g.
process-,variables process-andeach media. See Data processors for the complete list. - Example
dataProcessing { 10 = database-query 10 { table = tx_myext_domain_model_item as = items } 20 = process-variables 20 { as = items merge = 1 variables { label = TEXT label.field = title } } }Copied!
preProcessing
- Type
- array
- Description
- Data source aware processors
executed before
variablesare processed. These can read from multiple data sources (content element record, processed data, processor configuration) and modify the variable set before content object rendering begins.
postProcessing
- Type
- array
- Description
- Data source aware processors
executed after
variableshave been resolved and data processors have run, but before the template is rendered.
assets
- Type
- array
- Description
- Registers JavaScript and CSS assets via TYPO3's Asset collector
API. Supports four sub-keys:
java,Script inline,Java Script css,inline.Css - Example
assets { javaScript { my-ext-app { source = EXT:my_extension/Resources/Public/JavaScript/app.js attributes.defer = 1 options.useNonce = 1 } } css { my-ext-styles { source = EXT:my_extension/Resources/Public/Css/styles.css } } }Copied!
See also
Asset management for the complete assets configuration reference.
headerAssets
- Type
- content object
- Description
- Adds arbitrary markup to the page
<head>. The value is evaluated as a content object and the result is passed toPage.Renderer:: add Header Data () - Example
headerAssets = TEXT headerAssets.value = <link rel="stylesheet" href="/assets/styles.css">Copied!
stdWrap
- Type
- stdWrap
- Description
- Standard TYPO3 stdWrap processing applied to the final rendered output.
- Example
stdWrap.wrap = <div class="handlebars-content">|</div>Copied!