Skip to content
Open in

Export Options ​

What a save produces ​

Every save produces two artifacts, and both arrive through the save callbacks:

  • JSON definition: the editable template structure. It comes straight from the editor's memory, with no network call. Store it so the page can be loaded back into the editor later with load().
  • Rendered HTML: the production-ready page. Rendering happens server-side: the editor sends the template definition to Topol's API and receives the finished HTML back, so HTML export requires a network connection to Topol's services.

Both are handed to your application through the onSave and onSaveAndClose callbacks, which are passed as top-level properties next to config:

js
const LPE = LandingPageEditor({
  config: TOPOL_OPTIONS,
  onSave: ({ json, html }) => {
    // json = template definition, html = rendered page as a string
    // persist both on your server
  },
  onSaveAndClose: ({ json, html }) => {
    // persist, then tear down the editor UI in your app
  },
});
LPE.render("#landing-page-editor");

A save (and therefore an export) can also be triggered programmatically from your application code:

js
LPE.save();

If the rendering request fails, the editor shows an error notification and onSave is not called.

Persisting asynchronously ​

Both save callbacks may return a Promise. The editor keeps its saving state (spinner, disabled button) until the Promise settles, so the user sees the save as finished only once your backend has actually stored the page:

js
const LPE = LandingPageEditor({
  config: TOPOL_OPTIONS,
  onSave: async ({ json, html }) => {
    const res = await fetch("/api/pages/42", {
      method: "PUT",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ json, html }),
    });
    if (!res.ok) throw new Error(`Save failed: ${res.status}`);
  },
  onSaveAndClose: async ({ json, html }) => {
    await persistPage(json, html); // throws on failure
    closeEditorPanel(); // only reached when persisting succeeded
  },
});
  • A rejected Promise (or a thrown error) is reported to the user as a save error; for onSaveAndClose it also keeps the editor open.
  • A Promise that never settles is released after 30 seconds, so a broken host handler cannot wedge the editor. The editor then tells the user that the save hasn't been confirmed, and the page stays marked as unsaved.
  • Returning nothing keeps the previous fire-and-forget behaviour.
  • Without an onSaveAndClose handler, Save & Close delivers the payload to onSave and then removes the editor iframe.

One save at a time ​

The editor runs one save at a time. LPE.save() returns a Promise that settles after the render finished and your onSave Promise settled, so the onSave that fires while it is pending is the answer to that call. Calling LPE.save() while a save is still running (yours, or one started from the Save button) rejects with an error whose code is "SAVE_IN_PROGRESS" and fires no onSave.

js
try {
  await LPE.save();
} catch (err) {
  if (err.code === "SAVE_IN_PROGRESS") {
    // A save is already running; its onSave carries the current page.
  }
}

The rejection reaches your page as a plain Error, because the editor runs in an iframe and an error's class does not survive the crossing. Check err.code rather than instanceof or the message text.

Every other outcome resolves the LPE.save() Promise, so the callbacks tell success from failure. When the render fails, onSave does not fire and onEditorError fires with source: "save". When your onSave Promise rejects, onSave has already fired, and the editor then shows its saving error and fires onEditorError with source: "save" and detail.stage: "host". An onSave Promise that is still pending after 30 seconds is released without an error: the editor shows a notice that the save was not confirmed and keeps the page marked as unsaved.

If the editor's own Ctrl/Cmd+S should not start saves either, add the disableShortcuts option.

WARNING

The editor also has a reserved internal property named export; it belongs to the iframe plumbing and is unrelated to template export. Use onSave/onSaveAndClose to receive exported pages.

htmlMinified ​

The htmlMinified option (boolean, default false) minifies the rendered HTML by removing unnecessary whitespace:

typescript
{
  htmlMinified: true
}

Minified output is smaller but harder to read and debug. The flag applies to preview HTML as well, not only to saved exports.

Rendering outside the editor ​

The same rendering service is available as a REST endpoint for producing a page's HTML server-side from a stored JSON definition without opening the editor: JSON to HTML (secret key) authenticates with the X-Secret-Key header and reports fonts missing from the page, which makes it the right choice for backend jobs. JSON to HTML (API key) is the endpoint the editor itself calls, authenticated with the public API key and hostname.