Skip to main content

template

Render Mustache templates to generate dynamic strings, HTML, or structured payloads.

Overview

The template node uses Mustache syntax to render dynamic strings from message properties. Build HTML emails, format notification text, construct dynamic MQTT topics, or generate any text output by referencing msg.payload, msg.topic, and all payload fields within double-brace placeholders.

Mustache
Syntax
Plain
Text Mode
Loops
& Sections
HTML
Safe Output

Properties

Property Type Default Description
template string "" Mustache template string with placeholders
field string "payload" Target property on msg to store the rendered output
syntax string "mustache" "mustache" for template rendering or "plain" for literal text

Mustache Syntax Guide

Variable Interpolation

Insert values from the template context

Temperature: {{payload.temperature}}°C
Device: {{topic}}
Time: {{payload.timestamp}}

Sections (Conditionals)

Render blocks when a value is truthy

{{#payload.alert}}
  WARNING: {{payload.message}}
{{/payload.alert}}
{{^payload.alert}}
  All systems normal.
{{/payload.alert}}

Loops (Arrays)

Iterate over arrays in the payload

Sensors:
{{#payload.sensors}}
  - {{name}}: {{value}} {{unit}}
{{/payload.sensors}}

Unescaped HTML

Use triple braces for raw HTML output

// Escaped (default)
{{payload.html}}
// → <b>Hello</b>

// Unescaped
{{{payload.html}}}
// → <b>Hello</b>

Example: HTML Email Template

Generate a formatted HTML alert email from sensor data.

// Template node configuration
{
  "template": "<html><body><h2>Alert: {{topic}}</h2><p>Temperature reading of <strong>{{payload.temperature}}°C</strong> exceeds threshold.</p><table border='1'><tr><td>Device</td><td>{{payload.device}}</td></tr><tr><td>Location</td><td>{{payload.location}}</td></tr><tr><td>Time</td><td>{{payload.timestamp}}</td></tr></table></body></html>",
  "field": "payload",
  "syntax": "mustache"
}

// Input message
{
  "topic": "greenhouse/zone-a",
  "payload": {
    "temperature": 42.3,
    "device": "sensor-07",
    "location": "Zone A - Row 3",
    "timestamp": "2025-06-15T14:30:00Z"
  }
}

// Output: msg.payload now contains the rendered HTML string
// Ready to pass to an email node or HTTP POST

Example: Dynamic MQTT Topic Construction

Build MQTT topics dynamically from device metadata in the payload.

// Template node configuration
{
  "template": "devices/{{payload.region}}/{{payload.device_type}}/{{payload.device_id}}/telemetry",
  "field": "topic",
  "syntax": "mustache"
}

// Input message
{
  "payload": {
    "region": "eu-west",
    "device_type": "temperature",
    "device_id": "sens-042",
    "value": 23.7
  }
}

// Output: msg.topic = "devices/eu-west/temperature/sens-042/telemetry"
// msg.payload unchanged — ready for MQTT out node

Example: Multi-Sensor Report with Loops

Generate a plain-text report iterating over an array of sensor readings.

// Template node configuration
{
  "template": "=== Sensor Report ===\nGenerated: {{payload.generated}}\n\n{{#payload.sensors}}[{{id}}] {{name}}: {{value}} {{unit}}\n{{/payload.sensors}}\nTotal sensors: {{payload.count}}",
  "field": "payload",
  "syntax": "mustache"
}

// Input message
{
  "payload": {
    "generated": "2025-06-15 14:30",
    "count": 3,
    "sensors": [
      { "id": "S1", "name": "Temperature", "value": 24.5, "unit": "°C" },
      { "id": "S2", "name": "Humidity", "value": 62, "unit": "%" },
      { "id": "S3", "name": "Pressure", "value": 1013, "unit": "hPa" }
    ]
  }
}

// Output: formatted text report string

Common Use Cases

Email Formatting

Generate HTML or plain text alert emails with dynamic data

MQTT Topics

Build publish/subscribe topics from message properties

API Payloads

Construct JSON or XML request bodies for HTTP nodes

Dashboard Widgets

Render HTML fragments for UI display nodes

Related Nodes