Skip to main content

Interface: TemplateEngine

ghostly-engine.TemplateEngine

The Template Engine API.

Methods

render

render(document, contentType, format, params?, onGhostlyEvent?): Promise<Buffer>

Render a single view from a model (with no attachments) and return the result as a Buffer.

throws GhostlyError Template-related errors.

throws Error Other internal errors.

Parameters

NameTypeDescription
documentstring | objectThe model to render.
contentTypestringThe model's media type.
formatstringThe media type of the view to render (text/html, image/png, application/pdf ...).
params?unknownOptional view params as parsed JSON.
onGhostlyEvent?OnGhostlyEventOptional callback to invoke if the template emits an event using notify.

Returns

Promise<Buffer>

A Buffer containing the rendered document.

Defined in

ghostly-engine/src/engine.ts:125


renderRequest

renderRequest(request, onGhostlyEvent?): Promise<RenderResult[]>

Render multiple views and/or attachments from a model and return the results as a RenderResult array.

throws GhostlyError Template-related errors.

throws Error Other internal errors.

Parameters

NameTypeDescription
requestRenderRequestRender parameters/options.
onGhostlyEvent?OnGhostlyEventOptional callback to invoke if the template emits an event using notify.

Returns

Promise<RenderResult[]>

A Buffer containing the rendered document.

Defined in

ghostly-engine/src/engine.ts:136


renderViews

renderViews(document, contentType, views, attachments, onGhostlyEvent?): Promise<RenderResult[]>

Render multiple views and/or attachments from a model and return the results as a RenderResult array.

throws GhostlyError Template-related errors.

throws Error Other internal errors.

deprecated Use renderRequest instead.

Parameters

NameTypeDescription
documentstring | objectThe model to render.
contentTypestringThe model's media type.
viewsView<unknown>[]View definitions.
attachmentsbooleanSet to true if you also want to render the attachments (if any).
onGhostlyEvent?OnGhostlyEventOptional callback to invoke if the template emits an event using notify.

Returns

Promise<RenderResult[]>

A Buffer containing the rendered document.

Defined in

ghostly-engine/src/engine.ts:151