Change SVG color in ui-template node with msg.payload?

Noob here.

I used a ui-template node to create an SVG circle.

I used a JS script to set the circle's fill color.

I used an if statement to change the fill color with msg.payload, which comes in as a number specified using an injector node.

Everything works fine if I replace msg.payload with a number (to test the code). But nothing works if I try to use msg.payload to control the circle's color.

Is it not possible to access msg.payload in ui-template nodes? Is there magic sauce I need to apply for it to work?

Hi Alex,
There are some examples around, like e.g. this one ...

And you can also use the node-red-contrib-ui-svg node, where we have already figured out most of this kind of the stuff in advance... Then you simply can inject a color, as described here.

Ah! Thanks, @BartButenaers! This seems just the thing I needed. Big thanks for the pointers :grinning:

1 Like