Display text in dashboard from string getting from a function

Hi Forum,

first of all, I am a newbie.

I am trying to display a text in the dashboard in the color I get from a function.

here once the template:

<body>
  <p style="color": msg.payload >test</p>
</body>

and here the function:

var newMSG = msg.payload;

if(newMSG == 5) msg.payload = "red";
else if(newMSG == 6) msg.payload = "green";
else if(newMSG == 7) msg.payload = "blue";
else if(newMSG == 8) msg.payload = "white";

return msg;

can someone help me with this :)?

Thanks already

greetings

<p style="color: {{ msg.payload }}"> test </p>

Hi,

thanks for the answer, but that doesn't work :frowning:
Is maybe the function not correct?

greetings

Tested, it works. Try injecting a color string in the template and you'll see.

try this, inject a color and watch into the Dashboard "Generale -> Test" group:

[{"id":"b305344b25b4adaf","type":"ui_template","z":"fd95058a.48e3e8","group":"f5dc3cef6c5ab80d","name":"","order":0,"width":0,"height":0,"format":"<p style=\"color: {{ msg.payload }}\"> test </p>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","className":"","x":410,"y":1300,"wires":[[]]},{"id":"f4c502f1fcabc14a","type":"inject","z":"fd95058a.48e3e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"red","payloadType":"str","x":240,"y":1280,"wires":[["b305344b25b4adaf"]]},{"id":"cbc39f2172ab4269","type":"inject","z":"fd95058a.48e3e8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"green","payloadType":"str","x":250,"y":1340,"wires":[["b305344b25b4adaf"]]},{"id":"f5dc3cef6c5ab80d","type":"ui_group","name":"Test","tab":"cb8604ed.917408","order":11,"disp":true,"width":"6","collapse":false,"className":""},{"id":"cb8604ed.917408","type":"ui_tab","name":"Generale","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

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