Using global variables in a paragraph / template

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.

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}} ...

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.

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

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 :


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:

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

( just out putting the previous template, right? )

Final output for the dashboard:

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.

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

I had better luck with

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

1 Like

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