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
| Name | Type | Description |
|---|---|---|
document | string | object | The model to render. |
contentType | string | The model's media type. |
format | string | The media type of the view to render (text/html, image/png, application/pdf ...). |
params? | unknown | Optional view params as parsed JSON. |
onGhostlyEvent? | OnGhostlyEvent | Optional 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
| Name | Type | Description |
|---|---|---|
request | RenderRequest | Render parameters/options. |
onGhostlyEvent? | OnGhostlyEvent | Optional 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
| Name | Type | Description |
|---|---|---|
document | string | object | The model to render. |
contentType | string | The model's media type. |
views | View<unknown>[] | View definitions. |
attachments | boolean | Set to true if you also want to render the attachments (if any). |
onGhostlyEvent? | OnGhostlyEvent | Optional callback to invoke if the template emits an event using notify. |
Returns
Promise<RenderResult[]>
A Buffer containing the rendered document.