Skip to content

Dynamic label via Mustache expressions

bartbutenaers edited this page Aug 31, 2021 · 1 revision

It is possible to have a fixed label, or change the label dynamically via input messages.

In order to have a dynamic label, Mustache expressions inside the label can be used. This is functionality that some other standard Node-RED nodes also offer, like e.g. the http-request node...

This example Mustache expression combines both a fixed and a dynamic part:

config page

The following demo flow shows how this works:

demo

[{"id":"af99e9bc99fa8665","type":"ui_multistate_switch","z":"3e329e777a5729f1","name":"","group":"053ab09a43c0a541","order":2,"width":0,"height":0,"label":"Label {{label}}","stateField":"payload","enableField":"enable","passthroughField":"passthrough","inputMsgField":"inputmsg","rounded":false,"useThemeColors":true,"hideSelectedLabel":false,"multilineLabel":false,"passThrough":"never","inputMsg":"all","userInput":"enabled_show","options":[{"label":"Option 0","value":"option_0","valueType":"str","color":"#009933"},{"label":"Option 1","value":"option_1","valueType":"str","color":"#999999"}],"x":1600,"y":1060,"wires":[[]]},{"id":"60aa9cd5cca83dfe","type":"inject","z":"3e329e777a5729f1","name":"Label with \"one\"","props":[{"p":"label","v":"one","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1380,"y":1060,"wires":[["af99e9bc99fa8665"]]},{"id":"c97f10422c72fcd8","type":"inject","z":"3e329e777a5729f1","name":"Label with \"two\"","props":[{"p":"label","v":"two","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":1380,"y":1100,"wires":[["af99e9bc99fa8665"]]},{"id":"053ab09a43c0a541","type":"ui_group","name":"Mustache label demo","tab":"3667e211.c08f0e","order":2,"disp":true,"width":"6","collapse":false},{"id":"3667e211.c08f0e","type":"ui_tab","name":"Showcase","icon":"dashboard","order":1,"disabled":false,"hidden":false}]