Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.51 KB

File metadata and controls

49 lines (35 loc) · 1.51 KB

Directus Live Preview Sync

An interface to push realtime updates to the live preview iframe.

Tested with Directus 10.10.4

Usage

This extension pushes live value updates to the live preview iframe.

Example Code: example endpoint

Requirements:

  1. Set the Live Preview URL Set the Live Preview URL
  2. Add the Live Preview Sync interface Add Live Preview Sync interface

Message Structure

{
  "type": "directus-preview",
  "path": "/admin/content/<collection>/<id>",
  "values": <form-values>,
}

Updating the Preview Page

For this to work the live preview page needs to be listening for the events. On the preview page add code with the following bootstrap:

window.addEventListener("message", (event) => {
    const { type, path, values } = event.data;
    if (type === 'directus-preview') {
        // do something creative
    }
}, false);

Examples

Included Example Example Demo

Random Map Example Dynamic Map Demo