FleetbaseFleetbase

TemplateBuilder

<TemplateBuilder> is a drag-and-drop layout editor for HTML templates with variable interpolation. Used by Ledger invoice templates and any template-driven feature.

<TemplateBuilder>

<TemplateBuilder> is a complete drag-and-drop editor for designing templates that mix static layout with dynamic variables. It's the engine behind Ledger's invoice templates and is reusable for any template-driven feature.

The builder supports text, images, tables, lines, shapes, QR codes, and barcodes — each freely positioned, rotated, and styled. Variables (e.g. {invoice.number}, {transaction.reference}) are inserted via a variable picker that's powered by context schemas registered with the template render service.

Basic Usage

<TemplateBuilder
  @template={{this.template}}
  @contextSchemas={{this.contextSchemas}}
  @isSaving={{this.isSaving}}
  @onSave={{this.saveTemplate}}
  @onPreview={{this.previewTemplate}}
  @onClose={{this.exitBuilder}}
/>

Arguments

ArgumentTypeDescription
@templatemodelThe template record being edited
@contextSchemasarraySchemas describing the variables available — typically supplied by the host extension
@isSavingbooleanDrives the save button's loading state
@onSave() => PromiseSave callback
@onPreview() => voidPreview callback (renders against sample data)
@onClose() => voidOptional — back/exit button callback
@closeIconstringDefault chevron-left
@closeLabelstringOptional close button label

Element Types

The toolbar lets the user drop the following onto the canvas:

TypeDescription
TextStatic or variable-driven text with font, size, color, alignment
ImageLogo, photo, or arbitrary image URL
TableTabular layout for line-item style rendering
LineHorizontal or vertical separator
ShapeRectangle, circle, etc.
QR CodeQR code generated from a value
BarcodeBarcode generated from a value

Tracked State

The builder maintains:

PropertyDefaultDescription
selectedElementCurrently-selected element
zoom1Canvas zoom level (range 0.25–3)
variablePickerOpenfalseWhether the variable picker is open
_undoStack / _redoStackUp to 50 undo steps
leftPanelTablayerslayers or queries

Paper Sizes

A4, A3, A5, Letter, Legal — selectable from the canvas settings.

Real-World Example

In Ledger, the invoice template editor wraps <TemplateBuilder>:

<TemplateBuilder
  @template={{@template}}
  @contextSchemas={{this.contextSchemas}}
  @isSaving={{this.saveTemplate.isRunning}}
  @onSave={{perform this.saveTemplate}}
  @onPreview={{this.preview}}
  @closeIcon="chevron-left"
  @onClose={{transition-to "billing.invoice-templates"}}
/>

Variables in the picker resolve at render time against the chosen invoice via TemplateRenderService::registerContextType('invoice', { … }) on the server-provider side.

See Also

Source

FileDescription
addon/components/template-builder.hbsTemplate
addon/components/template-builder.jsClass — extensive JSDoc, start there for advanced extension
addon/components/template-builder/Subcomponents
TemplateBuilder | Fleetbase