Skip to content

Template

For anything the built-in widgets don’t cover: a tank drawing, a machine diagram, a custom control. You write HTML with optional <style> and <script> blocks, or a Svelte component, and the tile renders it. It keeps the theme and works like any other widget: msg.payload in, send() out, msg.ui for props.

To reuse a component across projects or share it on npm, make it a widget package instead.

The template above is the whole widget. Press Drain to see the message it sends.

Property Type Default Description
label string Optional title; without it the template fills the whole tile
icon string Lucide icon before the title
format html | svelte html How the template is written
frame boolean true The tile’s background, border and padding. Turn it off when the template draws its own card, so it doesn’t look like a card inside a card
template string a small example The HTML (with optional <style> and <script> blocks), or the Svelte component
topic (node config) string msg.topic of what the script sends

HTML goes first. It renders in a Shadow DOM, so your styles stay inside the tile and the dashboard’s styles stay out.

<style>: plain CSS, scoped to the template.

  • :host is the tile’s content area.
  • The theme tokens are inherited and follow the dark and light themes: var(--fg), var(--muted), var(--faint), var(--accent), var(--accent-soft), var(--surface), var(--surface-2), var(--line), var(--line-strong), var(--ok), var(--warn), var(--alarm).
  • The content has a padding like other widgets. To go edge to edge, set :host { --tile-pad: 0 }, or turn off frame to drop the tile’s background and border too.
  • The tile is as tall as its rows, not as its content: if the template needs more room, it scrolls. Make the tile taller in the builder, or make the template fit (height: 100%, flex).
  • Browsers give headings and paragraphs default margins inside the template (the dashboard’s reset doesn’t reach a Shadow DOM): set margin: 0 where you don’t want them.

<script> runs once, when the tile is shown (and again if the template changes). Top-level await works. It gets:

Name What it is
root The shadow root: find your elements with root.querySelector(…)
on('message', fn) fn({ payload, topic }) for every message. Also called once at the start with the last message stored, so one handler covers both.
on('props', fn) fn(props) when msg.ui changes the props
on('destroy', fn) Clean up timers and listeners: the tile is going away or the template changed
send(payload) Sends msg.payload from the node’s output
w.props, w.state The current props, and the last message stored ({ payload, topic })
<span class="clock"></span>
<script>
const el = root.querySelector('.clock');
const tick = () => (el.textContent = new Date().toLocaleTimeString());
tick();
const timer = setInterval(tick, 1000);
on('destroy', () => clearInterval(timer));
</script>

Errors in the script, including in your handlers, show in the tile with the template line. The rest of the page keeps working.

With Format: Svelte, the template is a Svelte 5 component, written with runes. It gets two props:

  • w: w.props (label, icon, anything from msg.ui) and w.state, the last message stored ({ payload, topic }, or null before the first one);
  • send(payload): sends msg.payload from the node’s output.
  • Styles are scoped by Svelte and stay inside the tile; the theme tokens work as in HTML templates.
  • Templates can import from Svelte itself: svelte, svelte/transition, svelte/easing, svelte/animate, svelte/motion, svelte/store, svelte/reactivity, svelte/events and svelte/attachments. Nothing else: no npm packages, no URLs (dashboards often run offline).
  • Compile errors show in the tile with the line; so do errors while rendering.
msg.payload = 72; // any value: stored and passed to on('message')
msg.payload = { level: 72, pump: 'run' };
msg.ui = { label: 'Tank 4' }; // props, as with every widget
msg.ui = { template: '<b>New content</b>' }; // even the template

The last message is stored, so a browser that opens the dashboard later gets it too. With msg._client, it goes to one browser only and isn’t stored.

What the script passes to send():

{ payload: 'drain', topic: 'tank3', _client: { id: 'c1-…' } }