When beginner users write Mustache in template node, they tend to encounter problems to specify array index. For example:
- How to access array element by index in mustache in template node - #4 by Steve-Mcl
- Node-REDのmustacheテンプレートで配列の要素にインデクス番号でアクセスする
The current template node supports only dot name (e.g. payload.array.0
) and doesn't support bracket name (e.g. payload.array[0]
). Therefore, they especially have problems when they use variable paths copied from debug tab.
Example flow
Example flow data
[{"id":"c6f6377add70d8fb","type":"inject","z":"43fab81c88fde8bf","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"array\":[\"a\",\"b\",\"c\"]}","payloadType":"json","x":150,"y":100,"wires":[["2034d76315d03923","d2097a4024a1b6ed"]]},{"id":"2034d76315d03923","type":"debug","z":"43fab81c88fde8bf","name":"output array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":370,"y":100,"wires":[]},{"id":"d2097a4024a1b6ed","type":"template","z":"43fab81c88fde8bf","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"This is the payload: {{payload.array[0]}} !","output":"str","x":200,"y":180,"wires":[["0e4939f974791cf9"]]},{"id":"0e4939f974791cf9","type":"debug","z":"43fab81c88fde8bf","name":"output 1st character in array","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":420,"y":180,"wires":[]}]
Because the Mustache engine will not handle the bracket name, I hope that Node-RED supports both the dot and bracket style by replacement implementation.