# Template Node Variables

**URL:** https://discourse.nodered.org/t/template-node-variables/94576
**Category:** Dashboard
**Tags:** node-red-dashboard
**Created:** [13 January 2025 13:15 UTC](https://discourse.nodered.org/t/template-node-variables/94576 "2025-01-13T13:15:44Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![LucasPelu](https://avatars.discourse-cdn.com/v4/letter/l/977dab/32.png) [@LucasPelu](https://discourse.nodered.org/u/LucasPelu)
#### Post date: [13 January 2025 13:15 UTC](https://discourse.nodered.org/t/template-node-variables/94576/1 "2025-01-13T13:15:44Z")

</div>

Good morning, I am facing a problem perhaps due to lack of knowledge.  
I am working on a dashboard with different template nodes.  
In a template node I fill a form with data.  
Then in another template I made a restriction on an input based on the data entered in the forms of the other node.  
My question is how I can have a "global" variable between the template nodes. This way in one node I save the variable and in another node I bring it and use it.  
I hope I have explained myself.  
Greetings and thanks

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [13 January 2025 15:25 UTC](https://discourse.nodered.org/t/template-node-variables/94576/2 "2025-01-13T15:25:00Z")

</div>

> [@LucasPelu](#):
>
> My question is how I can have a "global" variable between the template nodes. This way in one node I save the variable and in another node I bring it and use it.

The best way to pass data to your template node is as a message property.

Here is an example using msg.payload.location and msg.payload.forecasttime:

```auto
<div class="location">
      <div class="placename">
            {{msg.payload.location}}
      </div>
      <div class="forecasttime">
             &VeryThinSpace;@&VeryThinSpace;{{msg.payload.forecasttime}}
      </div>
</div>

```

Yes Node-red does also offer context variables and environment variables.

You should always try and use message properties instead of these, but if you must, at least don't use a global variable unless you really need it to have global scope.

---

<div class="post-metadata">

### Author: ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)
#### Post date: [13 January 2025 16:59 UTC](https://discourse.nodered.org/t/template-node-variables/94576/3 "2025-01-13T16:59:07Z")

</div>

When you say "Global", are you referring to sharing variables between templates **within the same client**?. If that is the case, you can always set your variables as properties of the `window` object, or store them in hidden HTML elements and read their value them (in any template) using `document.getElementById()`.

---

<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: [12 February 2025 16:59 UTC](https://discourse.nodered.org/t/template-node-variables/94576/4 "2025-02-12T16:59:41Z")

</div>

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