The "Template" node is used to create and manipulate text templates. For example for generating HTML, configuration files, our other text based strings. The Template node allows you to generate dynamic content by injecting data into predefined templates using the Mustache templating language. When there's no need for dynamic templates, the Format can be set to Plain Text, which has a slight performance benefit.

How the Template node works

Input Data

You can connect the Template node to a source of data, such as an MQTT input, HTTP input, or any other node that provides data. This input data will be used to populate the template.

Template Definition

In the Template node configuration, you define the template using text based formatting languages like HTML with the Mustache syntax. Mustache is a simple and "logic-less" templating language that allows you to insert variables and expressions into your template.

For example, you can define a template like this: <p>Hello {{payload.name}}!</p>.

HTML Template with Mustache

[{"id":"97d742eec1cb7dbf","type":"inject","z":"a6b7ede2e13fcbdf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\": \"FlowFuse\"}","payloadType":"json","x":180,"y":60,"wires":[["c85d70b41f374f02"]]},{"id":"c85d70b41f374f02","type":"template","z":"a6b7ede2e13fcbdf","name":"Template using payload.name","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<p>Hello {{payload.name}}!</p>","output":"str","x":450,"y":60,"wires":[["6df7215459dfb240"]]},{"id":"6df7215459dfb240","type":"debug","z":"a6b7ede2e13fcbdf","name":"Print \"<p>Hello, FlowFuse!</p>\"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":60,"wires":[]}]

This example will output <p>Hello FlowFuse!</p>.


When the Template node receives input data, it processes the data and replaces Mustache placeholders with the corresponding values from the input data. The resulting HTML or text is then sent as output to the next node in the flow.

Building JSON

The template node can be configured to parse the result of the input and template as JSON, to further use the message as an object, not as string.

Input data

payload: ['ACME', 1]

Template node configuration

  • Template:
    "product": "{{payload.0}}",
    "version": {{payload.1}}
  • Format: Mustache template
  • Output as: Parsed JSON


{ "product": "ACME", "version": 1 }

Generating JavaScript object from YAML

Node-RED can also parse YAML

Input data

topic: 'FlowFuse',
payload: 3000

template node configuration

  • Template:
    title: {{topic}}
    port: {{payload}}
  • Format: Mustache template
  • Output as: Parsed JSON


{ "title": "FlowFuse", "port": 3000 }


When a template gets larger, it might be useful to add comments to the template which will not appear in the output. Comments work about the same as the normal syntax, with a ! after the opening curly brackets:

{{! this won't show }}
This text will be in the output

Will result in This text will be in the output. Note there's no empty line character \n.

Mustache partials

Mustache by default supports partials to include. This is an unsupported feature in Node-RED.

Node Documentation

Sets a property based on the provided template.


msg object
A msg object containing information to populate the template.
template string
A template to be populated from msg.payload. If not configured in the edit panel, this can be set as a property of msg.


msg object
a msg with a property set by populating the configured template with properties from the incoming msg.


By default this uses the mustache format, but this can be switched off if required.

For example, when a template of:

Hello {{payload.name}}. Today is {{date}}

receives a message containing:

  date: "Monday",
  payload: {
    name: "Fred"

The resulting property will be:

Hello Fred. Today is Monday

It is possible to use a property from the flow context or global context. Just use {{flow.name}} or {{global.name}}, or for persistable store store use {{flow[store].name}} or {{global[store].name}}.

Note: By default, mustache will escape any non-alphanumeric or HTML entities in the values it substitutes. To prevent this, use {{{triple}}} braces.

If you need to use {{ }} within your content, you can change the characters used to mark the templated sections. For example, to use [[ ]] instead, add the following line to the top of the template:

{{=[[ ]]=}}

Using environment variables

The template node can access environment variables using the syntax:

My favourite colour is {{env.COLOUR}}.