# Using global variables in a paragraph / template

**URL:** <https://discourse.nodered.org/t/using-global-variables-in-a-paragraph-template/24299>\
**Category:** General\
**Created:** [6 April 2020 02:45 UTC](https://discourse.nodered.org/t/using-global-variables-in-a-paragraph-template/24299 "2020-04-06T02:45:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mixnode](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mixnode/32/98497_2.png) [@mixnode](https://discourse.nodered.org/u/mixnode)\
**Post date:** [6 April 2020 02:45 UTC](https://discourse.nodered.org/t/using-global-variables-in-a-paragraph-template/24299/1 "2020-04-06T02:45:22Z")

</div>

Hi, I have some global variables set.  
Like sun.rise. Seems to be in the context data.

I'd like to retrieve them and use them in a dashboard template, or in a function that is crafted to output to a template.

I've named the variables in a function node:

var sunSign = global.get('sun.sign');  
var sunRise = global.get('sun.rise');  
var sunSet = global.get('sun.set');

var moonSign = global.get("moon.sign");  
var moonPhase = global.get("moon.phase");  
var moonRise = global.get('moon.rise');  
var moonSet = global.get('moon.set');  
var moonIco = global.get('moon.ico');

Example wish of combined text and variable:

The sun (global.sun.glyph) is in (global.sun.sign)  
Sunrise-icon (global.sun.rise)  
Sunset -icon (global.sun.set)

(global.moon.phase) (global.moon.ico) in (global.moon.sign)

I'd like to use them in a paragraph like the above.  
Any direction on how to construct something like this would be super helpful.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 April 2020 08:28 UTC](https://discourse.nodered.org/t/using-global-variables-in-a-paragraph-template/24299/2 "2020-04-06T08:28:59Z")

</div>

Doesn't curly brackets work?

I'm not in front of a computer to check the built in help in the side bar but I'm certain is show there?

E.g....

The sun {{global.sun.glyph}} is in {{global.sun.sign}}  
Sunrise-icon {{global.sun.rise}} ...

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [6 April 2020 09:36 UTC](https://discourse.nodered.org/t/using-global-variables-in-a-paragraph-template/24299/3 "2020-04-06T09:36:43Z")

</div>

Just to expand on the reply from @Steve-Mcl, in case it wasn't clear, but you can use the example he shared in a `template` node to do this.

---

<div class="post-metadata">

**Author:** ![mixnode](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mixnode/32/98497_2.png) [@mixnode](https://discourse.nodered.org/u/mixnode)\
**Post date:** [6 April 2020 14:20 UTC](https://discourse.nodered.org/t/using-global-variables-in-a-paragraph-template/24299/4 "2020-04-06T14:20:36Z")

</div>

Yes! Very good. Thank you.  
I knew there was an answer. This will set me free to do a lot of what I've been wanting to do in the dashboard.

BTW there are two 'template' nodes in use below.  
[i 2020-04-06 at 8.05.01 AM|377x60](https://discourse.nodered.org/uploads/short-url/yQp7FGsAtAWmnTfh6CVqh1ff1QL.png)

One template node doing the work and one template dashboard UI showing it in the dashboard.  
I'm making use of the node-red-contrib-astrodata for the data if you're curious.

**Template node :**

```auto

The sun is in {{global.sun.sign}}<br />
Rise {{global.sun.rise}}<br />
Set {{global.sun.set}}<br />

{{global.moon.phase}} in {{global.moon.sign}}<br />

Rise {{global.sun.rise}}<br />
Set {{global.sun.set}}<br />

This is the payload: <br />
{{payload}} if you're into that sort of thing.

```

**Template UI ( Dashboard ) Node:**

```auto
<div ng-bind-html="msg.payload"></div>

```

( just out putting the previous template, right? )

Final output for the dashboard:

```auto
The sun is in Aries<br />
Rise 6:41 am<br />
Set 7:26 pm<br />

Increasing moon in Virgo<br />

Rise 6:41 am<br />
Set 7:26 pm<br />

This is the payload: <br />
[object Object] if you're into that sort of thing.

```

][  
Now I'm noticing that I'm not able to wrap the template info in a span for styling.  
I'm able, but it's not showing the style on the dashboard as it is with other elements.  
Surely I can add a little style in the template? But why doesn't it display _styled_ in the dashboard? Huh?

I guess I'm still looking for a way to write styled html while plugging in data {{global.sun.set}} here and there.

```auto
<span class="note">
Rise: {{global.sun.rise}} 
Set: {{global.sun.set}}
</span>

```

I had better luck with

```auto
<i class="note">
Rise: {{global.sun.rise}} 
Set: {{global.sun.set}}
</i>

```

---

<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:** [20 April 2020 14:20 UTC](https://discourse.nodered.org/t/using-global-variables-in-a-paragraph-template/24299/5 "2020-04-20T14:20:37Z")

</div>

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