# If statement ui template

**URL:** https://discourse.nodered.org/t/if-statement-ui-template/1471
**Category:** Dashboard
**Created:** [9 July 2018 23:57 UTC](https://discourse.nodered.org/t/if-statement-ui-template/1471 "2018-07-09T23:57:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Unpuertomex](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unpuertomex/32/655_2.png) [@Unpuertomex](https://discourse.nodered.org/u/Unpuertomex)
#### Post date: [9 July 2018 23:57 UTC](https://discourse.nodered.org/t/if-statement-ui-template/1471/1 "2018-07-09T23:57:17Z")

</div>

Hello - I've been dinking around with an if statement in the ui template for several days now and haven't been able to figure it out.

I'm trying to load an svg file base on the msg.payload from the darksky node.  
For example, if the msg.payload is partly-cloudy-day I want to load a svg titled partly-cloudy-day.svg, if the msg.payload is fog load fog-1.svg and so on. I made the changes required to setting.js httpStatic: 'C:\Users\unpue\public', I serve a background picture with this setup so I know it works.

I can open the link to the svg file on Chrome by looking it up like this  
[http://192.168.2.xxx:1880//weather-icons/weather/partly-cloudy-day.svg](http://192.168.2.xxx:1880//weather-icons/weather/partly-cloudy-day.svg)

This is the flow  
 ![snip_20180709182831](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bb8ad0a092669567c7fdbc1386cd3b4e05c2854b.png)

and here what I have in the template node, I removed the first \<div just left div in its place because it kept trying to load the svg and wouldn't just show the script.

```auto
<div> ng-if= "msg.payload === partly-cloudy-day"
img src="/weather-icons/weather/partly-cloudy-day.svg"
</div>

<div. ng-if="msg.payload === fog" 
img src="/weather-icons/weather/fog-1.svg"
</div>

<div> ng-if="msg.payload === sunny"
img src="/weather-icons/weather/day.svg"
</div>

```

this is what the msg.payload looks like  
 ![snip_20180709183109](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/36bfbe327f5fc8ddd8c8ad9738bb0cf3918e7eb5.png)

Appreciate the help!

---

<div class="post-metadata">

### Author: ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)
#### Post date: [10 July 2018 18:55 UTC](https://discourse.nodered.org/t/if-statement-ui-template/1471/2 "2018-07-10T18:55:45Z")

</div>

Whenever you want to post a block of code, paste it between two lines that contain only three backtics, such as ````` -- otherwise any html or svg elements may be rendered into the page. (If you edit your post and add those lines, you'll see what I mean and make it easier for us to read...)

As for the angular syntax, you need to compare the `msg.payload` string to another javascript string, when you use the 3 equal signs. Since you left the right side of the equation as a bare keyword, i think it's trying to interpret things like `fog` as a variable. Try this:

```auto
<div>
    <img ng-if="msg.payload === 'partly-cloudy-day'" src="/weather-icons/weather/partly-cloudy-day.svg">
    <img ng-if="msg.payload === 'fog'" src="/weather-icons/weather/fog-1.svg">
    <img ng-if="msg.payload === 'sunny'" src="/weather-icons/weather/day.svg">
</div>

```

Another less verbose technique would be to use a `change` or `function` node ahead of this `ui_template` node, adding another field (e.g "msg.icon"), and then substituting that directly into your img src attribute, like so:

`<img src="/weather-icons/weather/{{msg.icon}}.svg">`

_(at least I believe that syntax is correct -- ymmv)_

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [10 July 2018 22:06 UTC](https://discourse.nodered.org/t/if-statement-ui-template/1471/3 "2018-07-10T22:06:15Z")

</div>

Note we do include @rossoreed s weather-icons-lite built into dashboard, so wi prefix should make them available like fa icons

---

<div class="post-metadata">

### Author: ![Unpuertomex](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unpuertomex/32/655_2.png) [@Unpuertomex](https://discourse.nodered.org/u/Unpuertomex)
#### Post date: [10 July 2018 22:21 UTC](https://discourse.nodered.org/t/if-statement-ui-template/1471/4 "2018-07-10T22:21:03Z")

</div>

> [@shrickus](#):
>
> paste it between two lines that contain only three backtics

@shrickus, thank you for the tip on the backtics, I was clearly using them incorrectly. I will give your changes a try and report back.

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [10 July 2018 23:17 UTC](https://discourse.nodered.org/t/if-statement-ui-template/1471/5 "2018-07-10T23:17:39Z")

</div>

> [@dceejay](#):
>
> weather-icons

Awesome ! There are a tons of weather icons ! Thanks for sharing Dave.

Adding links for more information:

[https://erikflowers.github.io/weather-icons/](https://erikflowers.github.io/weather-icons/)

> **[GitHub - Paul-Reed/weather-icons: Node-red weather icons](https://github.com/Paul-Reed/weather-icons)**
>
> Node-red weather icons. Contribute to Paul-Reed/weather-icons development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![Unpuertomex](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unpuertomex/32/655_2.png) [@Unpuertomex](https://discourse.nodered.org/u/Unpuertomex)
#### Post date: [11 July 2018 01:30 UTC](https://discourse.nodered.org/t/if-statement-ui-template/1471/6 "2018-07-11T01:30:15Z")

</div>

> [@dceejay](#):
>
> Note we do include @rossoreed s weather-icons-lite built into dashboard, so wi prefix should make them available like fa icons

Thank you @dceejay I looked at them before and was inspired to place animated ones to bring life into the alarm panel I'm working on. I downloaded these from [amcharts.com](https://www.amcharts.com/free-animated-svg-weather-icons/) I'm using them with the script @shrickus corrected for me. Right now I have just one setup, as the weather conditions change the animated icon changes as well, next sets are to figure out how to show a 3 days forecast in a table, might be back asking for help on that one too, but I am learning. You can see the animation on this screenshot.

 ![alarmpanel](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f4b372a8ff1b695fb6da61fa22234453e0b542db.gif)
