3

How to send msg.payload from function node(tool) to template node(html)?

enter image description here

<html>
<head>
    <script type="text/javascript">
    // function test() {
    //      document.getElementById("test1").innerHTML = msg.payload;
    // }
    </script>
</head>
<body onload="test()">
    <h1 id="test1">{{msg.payload}}</h1>
</body>

roschach
  • 8,390
  • 14
  • 74
  • 124
FanLee
  • 135
  • 4
  • 11

1 Answers1

3

The problem is you are using {{msg.payload}} in the template node. The values pulled in via mustache are keyed from the msg object. So the correct mustache template is {{payload}}.

<head>
    <script type="text/javascript">
    // function test() {
    //      document.getElementById("test1").innerHTML = {{payload}};
    // }
    </script>
</head>
<body onload="test()">
    <h1 id="test1">{{payload}}</h1>
</body>

The Info sidebar in Node-RED gives examples of what to use.

hardillb
  • 54,545
  • 11
  • 67
  • 105