Skip to content
Open in

Loading and saving a template ​

Template data always lives on your system: Topol never stores it, so loading and saving both run through code you control.

The diagram below shows how the data moves between your system and the editor.

Diagram of how template data flows between your system and the Topol editor

Loading a template ​

The instance returned by TopolEmailEditor() exposes a load method. It takes one argument, the template, and accepts either a JSON string or a parsed object.

ts
const template = "..."; // template obtained from your system

editor.load(template);

Saving a template ​

The built-in top bar already has a save button, which is the simplest way to trigger a save. Pressing it runs the onSave callback, where the template is handed back for storing.

onSave receives a single payload object with the template JSON (json), the rendered HTML (html), the language mutations (mutations, an array of { code, primary }), and the synced-sections usage (syncedSections). The first two are what most integrations save.

If you return a Promise from onSave (for example by making it async and awaiting your API call), the editor keeps the save spinner visible until it settles — and shows a saving error if it rejects. See Callbacks for details.

ts
const TOPOL_OPTIONS = {
  authorize: {
    apiKey: "YOUR_API_KEY",
    entityId: "UserID",
  },
};

const editor = TopolEmailEditor({
  config: TOPOL_OPTIONS,
  onSave: function ({ json, html, mutations, syncedSections }) {
    // Store the json and html on your system
  },
});