Skip to main content

Overview

@reelevant-tech/content-sdk is the library the Content Editor is built on. It loads a Content template, resolves its dependencies (Datasources, Datagraph Object Families, Workflow values), and renders its pages to an image. The example below reads the live version of a Content, lists its pages and the sources it uses, and renders the first page to a PNG in Node.js.

Modes

Both modes use CanvasKit (WebAssembly). In Node.js, load the canvaskit.wasm bytes and call ContentSDK.initCanvasKit() before creating the SDK, as in the example: the call is cached, so the SDK’s own initialisation is then skipped.

Settings

Template model

sdk.pages, sdk.components, sdk.dependencies, sdk.conditionGroups and sdk.componentGroups edit each part. sdk.render draws the current page and exposes the previews of every page.

Editing and exporting

  1. Load a template with await sdk.use(template, pageId). Validate data coming from outside with validateTemplate() first.
  2. Make changes through the namespaces. Wrap several changes between sdk.startUpdate() and sdk.commitUpdate() to record them as one history entry (undo(), redo()), or call sdk.discardUpdate() to drop them.
  3. Call sdk.export() to get the resulting Template, and save it through the Contents API.
Do not export while sdk.hasPendingUpdate() is true: the template is then a draft with partially applied changes.

Errors