PayloadHosting is a JavaScript library that enables custom HTML interfaces (both full custom HTML templates and inline HTML field editors) to interact with Template Builder and Viz Pilot Edge. It provides access to the VDF (Viz Data Format) payload of a template, allowing you to create specialized UIs to edit template data, such as headlines, names and images for a news story.
This section contains the following pages:
Note: The full API documentation is distributed with Template Builder under the location: /app/templatebuilder/js/@vizrt/payloadhosting/dist/docs/index.html.
Use PayloadHosting with NPM
The payloadhosting module is available as an NPM package, making it easier to integrate into modern JavaScript and TypeScript projects. This method simplifies dependency management, improves development workflows, and enhances compatibility with build tools.
Install the package using
npm install "c:\...\js\@vizrt\payloadhosting".
Module-Based Import: Use ES module syntax for better structure:
import{ payloadhosting } from"@vizrt/payloadhosting";Type Support: The package includes
payloadhosting.d.ts, enabling IDE autocompletion and type checking.Maintainability: Updates and version control are handled via
package.json.Integration: Works well with modern JavaScript tooling such as Webpack, Vite, and Rollup.
Manually Include PayloadHosting in HTML
Note: payloadhosting.jscan be found under the ./js folder of the Template Builder installation path.
For projects that do not use NPM, payloadhosting.js can be included manually in an HTML file by adding a script tag:
<!doctype html><html> <head> <script src="./payloadhosting.js"></script> </head> <body>...</body></html>This approach ensures window.vizrt.payloadhosting is globally available to use in your scripts.
Communicating with the Template Script
A custom HTML page, either a full custom HTML template or an HTML panel in the fill-in form, can exchange messages with the template script. A message is any JSON compatible value (a string, number, boolean, null, array or object), and its meaning is agreed between the page and the script. For example, the page can ask the script for MOS data, or the script can tell the page that the element has been saved.
payloadhosting.postMessageToScript(message)sends a message to the template script, where it is received byvizrt.onHtmlPanelMessage. Messages sent while no script is ready are dropped.payloadhosting.setScriptMessageHandler(handler)sets the handler for the messages the script sends withvizrt.postHtmlPanelMessage, to this page or to all pages.payloadhosting.setScriptReadyHandler(handler)sets the handler that is called when a script is ready to receive messages from the page: when the script has been initialized, again when a new script starts (for example when another element is opened), and after the page has been loaded or reloaded. If a script is already ready when the handler is set, the handler is called immediately. It is never called for templates without a script.
The page and the script start independently, so ask the script for what the page needs from the ready handler:
const ph = vizrt.payloadhostingph.setScriptReadyHandler(() => ph.postMessageToScript({ get: "slug" }))ph.setScriptMessageHandler(message => { document.getElementById("slug").textContent = message.slug})ph.initialize(() => undefined)In the template script, the request can be answered like this:
vizrt.onHtmlPanelMessage = (message, panelName) => { if (typeof message === "object" && message !== null && !Array.isArray(message) && message.get === "slug") { vizrt.postHtmlPanelMessage({ slug: vizrt.$pilot.mos.slug ?? "" }, panelName) }}A full custom HTML template is the only HTML panel of the template, so the script can leave out the panel name when it sends messages to it. HTML panels in the fill-in form are named by the name given in the template (for example map), which the script receives with each message. Only loaded panels receive messages from the script: the panels in the active view, or the full custom HTML page. See Communicating with HTML Panels for the script side.
Note: Communicating with the template script requires payloadhosting 2.3.0 or later.