The thanks template node? Displays the thank you for the client.
So as the msg travels from left to right
msg.payload starts being an object with the 2 vars
you then pass it through a template and change msg.payload to be your Thanks message
But your next node (the function node) then can't do a calculation on the to vars as you have just replaced them with the function node.
OK but then I don't understand because I used msg.payload.results so that the other data won't get destroyed. Where am I destroying the vars?
What does the 'thanks' template node do?
You are destroying the vars with the template node "thanks" that according to your screenshot puts the message in msg.payload as a string
I guess your "thank you" node is setting msg.payload
to be some html string, which is replacing the msg.payload
object (and all of its var1
, var2
, and results
properties).
Are you wanting to return the calculated difference in the rendered "thanks" page? That would make sense, so if you received bad data, you could change the output page to show the problem.
Either way, you cannot have 2 outputs wired into 1 http response
node. In the meantime, it might help if you understand more about javascript datatypes and object/array structures. I like the W3Schools introduction to JS datatypes, and their references dealing with JS Objects and JS Arrays. There are also some good examples of how to work with Node-RED msg objects specifically, in case you have not seen it.
Yes I'm trying to display the result in the thanks page. OMG, ok i dont know how I got so confused. So I moved the function node after the post node and connected the function node to the http response and it works now. So now how do I display the result in the thanks page?
At present the debug node shows the result and the http-response is giving a plain text html json as a result. I do understand objects, I just dont understand how the flow works in node-red, or not the flow but rather how to access things. So if the result is being passed in the message object to the http-response node, this is done automatically by node red and so simply setting the node's headers to content-type plain text, it will display the object in json format. The http-response node gets it because the function node passes it in its code "return msg;".
But how do I also send it to the thanks template html page, where I can work with html code and make the results prettier for the user?
I suggest you go read the 'info' tab of the template node....
ok great! I like your style:
-
So the post node sends the values in the msg object to the function node.
-
The function node stores them in msg.payload.var1 and var 2 and also processes the result and stores it in the msg.payload.result, so it passes {"var1":"33", "var2":"44", "result":"77"} the object to the objects downstream from it.
-
thanks template is one of those nodes and http-response is the other node that will get the msg object. The http-response node is getting it just fine, as a header content type and displaying it as text. But the thanks node is not getting it.
So I think I need to somehow capture that msg object in the thanks template html code. This is what I dont know how to do, Im not very well versed in html. Unless there is a different way I should be doing it?
Note, I edited my last post because you had found some of the answer, so now go read the info tab of the template node, you are almost there.
GOT IT!!!
<html>
<head>
</head>
<body>
{{payload.result}}
<h1>Thanks for signing up!</h1>
<p>You're all set.</p>
</body>
</html>
When I enter 22 and 33 and submit, I get 55 in the template debug node.
So the only problem I have now is that the json string displayed after clicking submit is the msg object presented by the http-response node. How do I make the thanks template to be the displayed node instead, so I can see my nice html result?
Looking around I found this which is nice: https://medium.com/node-red/node-red-design-patterns-893331422f42
Got it!
Good Job, you get an A+