Quick start
This page walks through a minimal working example: rendering a form built with the TYPO3 Form Framework using a single Handlebars template. It assumes the extension is already installed.
-
Include the site sets
Add the
cpsit/site set to your site configuration (see Site set), together with a site set providing content element rendering, e.g.handlebars- forms cpsit/:handlebars- content- element config/sites/<my-site>/config.yamldependencies: - cpsit/handlebars-content-element - cpsit/handlebars-formsCopied! -
Configure template paths
Declare where your
.hbsfiles are located using the site settings provided by thecpsit/site set (from EXT:handlebars), which is included automatically by thehandlebars cpsit/site set:handlebars- forms config/sites/<my-site>/settings.yamlhandlebars.view.templateRootPath: 'EXT:my_sitepackage/Resources/Private/Templates/Handlebars' handlebars.view.partialRootPath: 'EXT:my_sitepackage/Resources/Private/Partials/Handlebars'Copied!See also
Template paths in the EXT:handlebars documentation – all configuration methods and their priority order.
-
Configure TypoScript
Add a
datablock underProcessing plugin.that maps EXT:form renderables totx_ form. handlebars Forms. default HBS_*content objects. The array built by the processor becomes the Handlebars template context.The example below produces a
fieldsarray and anavarray from the current form page, plus aItems hiddenstring:Fields plugin.tx_form.handlebarsForms { default { dataProcessing { 10 = process-form 10 { formData { id = HBS_TAG id.attribute = id action = HBS_TAG action.attribute = action method = HBS_TAG method.attribute = method } fields = HBS_RENDERABLES fields { default { template = @form-field-generic id = HBS_TAG id.attribute = id name = HBS_TAG name.attribute = name label = HBS_LABEL value = HBS_TAG value.attribute = value } # Per-type overrides inherit from default via TypoScript copy operator Text < .default Text { template = @form-field-text } Email < .Text # Suppress Honeypot in the template; render it verbatim instead Honeypot { content = HBS_PASSTHROUGH } } navItems = HBS_NAVIGATION navItems { previousPage { label = HBS_LABEL name = HBS_TAG name.attribute = name value = HBS_TAG value.attribute = value } nextPage < .previousPage submit < .previousPage } hiddenFields = HBS_TAG } } } }Copied! -
Create a Handlebars template
Create the template file at the template root path declared above. The default template name is
Form(configurable via the handlebars_forms.view.templateName site setting), so the file must be namedForm..hbs The template receives the data built by the
process-processor directly as its context:form EXT:my_sitepackage/Resources/Private/Templates/Handlebars/Form.hbs<form id="{{formData.id}}" method="{{formData.method}}" action="{{formData.action}}" > {{#each fields}} {{#if template}} {{> (lookup . 'template')}} {{else if content}} {{this.content}} {{/if}} {{/each}} {{#each navItems}} {{> '@button' this}} {{/each}} {{hiddenFields}} </form>Copied!Tip
The
hiddenvalue is an HTML string (e.g. page index,Fields trusted, object identity). It is emitted by EXT:form'sProperties <f:view helper and must be output without escaping. In Handlebars this is done automatically when the value is aform> Safe– which is exactly whatString HBS_(used withoutTAG attribute) returns when wrapping tag content.Note
The partials referenced in this example (
@form-,field- generic @form-andfield- text @button) must be created in the partial root path as well. The@prefix looks up a partial by its bare filename, see Referencing templates and partials. -
Flush caches
After editing TypoScript or site settings, flush the TYPO3 caches.
Next steps
- Data processor – full reference for the data processor, including key resolution rules, conditions and TypoScript references
- Content objects – reference for all available
HBS_*content objects with their configuration options - Per-form overrides – use a different template or data structure for a specific form