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
- Load a template with
await sdk.use(template, pageId). Validate data coming from outside withvalidateTemplate()first. - Make changes through the namespaces. Wrap several changes between
sdk.startUpdate()andsdk.commitUpdate()to record them as one history entry (undo(),redo()), or callsdk.discardUpdate()to drop them. - Call
sdk.export()to get the resultingTemplate, and save it through the Contents API.
sdk.hasPendingUpdate() is true: the template is then a draft with partially applied changes.