Mustache array problem

Good evening,
i'm having some trouble about this: after a query in mysql i have this result payload[2][0]["@id"], i need to get this data in a html template using mustache.
How can i do it? {{payload.array.2.0.@id}} doesn't work.
Any ideas?

Thank you!

From the limited info
{{payload.2.0.@id}}
But can't be sure as i have no idea what your array really looks like.

Wow, it worked perfectly! Thank you so much!
May i ask something else? Can i use this value in a if statement in html?
For example: ( if {{payload.2.0.@id}} > 0 ) { some html }

There is a lambda function you could use. mustache(5) - Logic-less templates.
But, it may just be simpler to use a string literal template in a function node.

here is a example of three ways

[{"id":"d59e0171.98ced","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"[null,null,[{\"@id\":1}]]","payloadType":"json","x":130,"y":3920,"wires":[["f7e3199384a26e96","2a710bcb05a7a572","4af34fe8c4e91e62"]]},{"id":"f7e3199384a26e96","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"payload[2][0][\"@id\"]","pt":"msg","to":"$$.payload[2][0].`@id`> 0 ? \"<some html>\" : \"\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":3980,"wires":[["1f7af96e327ca29b"]]},{"id":"2a710bcb05a7a572","type":"function","z":"da8a6ef0b3c9a5c8","name":"function 20","func":"msg.payload = `<html>\n${(msg.payload[2][0][\"@id\"] > 0 ? \"<some html>\" : \"\")}\n</html>`\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":4080,"wires":[["00df87aa1a12b70e"]]},{"id":"4af34fe8c4e91e62","type":"function","z":"da8a6ef0b3c9a5c8","name":"function 21","func":"msg.wrapped =  function() {\n    return function(text, render) {\n      text = Number(render(text)) > 0 ? \"<some html again>\" : \"\"\n      return text\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":3920,"wires":[["71a414885e5a8651"]]},{"id":"96ebd467845b3c7c","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":"","topic":"","payload":"[null,null,[{\"@id\":0}]]","payloadType":"json","x":130,"y":4020,"wires":[["f7e3199384a26e96","2a710bcb05a7a572","4af34fe8c4e91e62"]]},{"id":"1f7af96e327ca29b","type":"template","z":"da8a6ef0b3c9a5c8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n{{{payload.2.0.@id}}}\n</html>","output":"str","x":600,"y":3980,"wires":[["00df87aa1a12b70e"]]},{"id":"00df87aa1a12b70e","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 228","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":3980,"wires":[]},{"id":"71a414885e5a8651","type":"template","z":"da8a6ef0b3c9a5c8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<html>\n{{#wrapped}}\n{{payload.2.0.@id}}\n{{/wrapped}}\n\n</html>","output":"str","x":540,"y":3920,"wires":[["00df87aa1a12b70e"]]}]
1 Like

Thank you so much E1cid, it's amazing!

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