Help with what I am seeing going through `template` node

(NOT the GUI one)

This is the code:

[{"id":"46f61a5c.0b4104","type":"inject","z":"280a6f57.28406","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":700,"wires":[["8cac52a0.8785c"]]},{"id":"8cac52a0.8785c","type":"moment","z":"280a6f57.28406","name":"","topic":"","input":"","inputType":"msg","inTz":"Australia/Sydney","adjAmount":0,"adjType":"days","adjDir":"add","format":"DD/MM/YY","locale":"en_AU","output":"","outputType":"msg","outTz":"Australia/Sydney","x":330,"y":700,"wires":[["660ee550.29552c"]]},{"id":"660ee550.29552c","type":"change","z":"280a6f57.28406","name":"Position","rules":[{"t":"set","p":"x","pt":"msg","to":"x","tot":"flow"},{"t":"set","p":"y","pt":"msg","to":"2","tot":"num"},{"t":"set","p":"separator","pt":"msg","to":"separator","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":120,"y":790,"wires":[["6917a797.4f08a8"]]},{"id":"6917a797.4f08a8","type":"string","z":"280a6f57.28406","name":"","methods":[],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":310,"y":790,"wires":[["f68e0e37.99ddf","2f55bb51.91bc84"]]},{"id":"f68e0e37.99ddf","type":"debug","z":"280a6f57.28406","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":420,"y":840,"wires":[]},{"id":"2f55bb51.91bc84","type":"template","z":"280a6f57.28406","name":"Template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{x}},{{y}}{{separator}}{{payload}}","output":"str","x":500,"y":790,"wires":[["4c369444.93aa04","fcc95cd.d2b51a"]]},{"id":"4c369444.93aa04","type":"link out","z":"280a6f57.28406","name":"","links":["81758ae7.d5bd6"],"x":605,"y":790,"wires":[]},{"id":"fcc95cd.d2b51a","type":"debug","z":"280a6f57.28406","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":740,"wires":[]}]

I want to get the date go through the template node.

Going in I see:

27/07/20

Coming out:
(given the flow values are set)

5,2@27/07/20

5 = x
2 = y
@ = separator

The / is being turned into .... &#x2f

Which I guess is the hex code for the /.

Sorry to ask the dumb question.

change your debug nodes to display the 'Complete msg object' and what do you see?

Well, I see this:

{"_msgid":"9a51bee1.e7b48","topic":"","payload":"5,2@27/07/20","x":5,"y":2,"separator":"@"}

(What happened with the copy/paste from the debug window and showing formatted payloads where it would look like what it does in the debug panel?)

Ok, in your sample, no msg.x is created because it comes from flow.x which does not exist in the flow you submitted. I will hard code t and take a look.

Check msg.separator as well! ("@")

Why are you using the string node? yoYou don't have any methods defined in it.


Sorry, I think that is an artefact from another effort.

Don't forget flow.separator !!

This is a bashup function node which gives the desired output:

msg.payload = msg.x + "," + msg.y + msg.separator + msg.mydom + "/" + msg.mymonthn + "/" + msg.myyear;
return msg;

For clarity:

If you look at the Info tab of the template node, you will see at the bottom

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

knowing that, what should your template node look like?

1 Like

ARGH!

Sorry. I've been here before. It is because I not using it that often, I forget.

Don't worry, we all forget things - I had to go looking for that tidbit myself :wink:

Looks good now.

I got a few problems nutted out. Things moving forward.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.