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

**URL:** https://discourse.nodered.org/t/change-svg-color-in-ui-template-node-with-msg-payload/41051
**Category:** Dashboard
**Created:** [15 February 2021 22:34 UTC](https://discourse.nodered.org/t/change-svg-color-in-ui-template-node-with-msg-payload/41051 "2021-02-15T22:34:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)
#### Post date: [15 February 2021 22:34 UTC](https://discourse.nodered.org/t/change-svg-color-in-ui-template-node-with-msg-payload/41051/1 "2021-02-15T22:34:35Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [16 February 2021 06:40 UTC](https://discourse.nodered.org/t/change-svg-color-in-ui-template-node-with-msg-payload/41051/3 "2021-02-16T06:40:49Z")

</div>

> [@a1ex](#):
>
> 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](https://flows.nodered.org/flow/2f1aaf0635f9bf23207152682323240a) one ...

And you can also use the [node-red-contrib-ui-svg node](https://github.com/bartbutenaers/node-red-contrib-ui-svg), 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](https://github.com/bartbutenaers/node-red-contrib-ui-svg/blob/master/docs/msg_control.md#updateset-a-style-attribute-value-via-msg).  
Bart

---

<div class="post-metadata">

### Author: ![a1ex](https://avatars.discourse-cdn.com/v4/letter/a/3be4f8/32.png) [@a1ex](https://discourse.nodered.org/u/a1ex)
#### Post date: [16 February 2021 06:49 UTC](https://discourse.nodered.org/t/change-svg-color-in-ui-template-node-with-msg-payload/41051/4 "2021-02-16T06:49:56Z")

</div>

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

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [18 March 2021 06:50 UTC](https://discourse.nodered.org/t/change-svg-color-in-ui-template-node-with-msg-payload/41051/5 "2021-03-18T06:50:22Z")

</div>

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