# How can i use the value of a variable i created inside the template node

**URL:** https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780
**Category:** Dashboard
**Tags:** node-red-dashboard
**Created:** [6 December 2021 14:51 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780 "2021-12-06T14:51:13Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 14:51 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/1 "2021-12-06T14:51:13Z")

</div>

I am new to node red and i created a variable inside the template node and i want to use its content in another node how can i do that?  
thank you in advance

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 15:04 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/2 "2021-12-06T15:04:08Z")

</div>

I am not sure what you mean by creating a variable inside a template node, but the usual method for getting data from one node to another is to pass it in a message.

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 15:06 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/3 "2021-12-06T15:06:28Z")

</div>

event inside a ui dashboard template node?

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 15:17 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/5 "2021-12-06T15:17:44Z")

</div>

> [@hanine](#):
>
> inside a ui dashboard template node

I assumed you meant a normal template node rather than ui-template. The ui\_template code runs in the browser, not the server, so again the only way to get it back to the server is to send it back via a message.

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 15:20 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/6 "2021-12-06T15:20:32Z")

</div>

No i mean the ui template node when i set a msg.variable it returns message undefined

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 15:27 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/7 "2021-12-06T15:27:44Z")

</div>

```auto
[
    {
        "id": "6459ddaad53aced2",
        "type": "ui_template",
        "z": "c4c2c6195e5e2f0a",
        "g": "91c080c74028ae64",
        "group": "ba4cd6c4f1b1c4ad",
        "name": "",
        "order": 5,
        "width": 0,
        "height": 0,
        "format": " <!DOCTYPE html>\n\n<html>\n<head>\n <title>Read File</title>\n</head>\n\n<body>\n<!-- <input type=\"file\" webkitdirectory directory multiple id=\"myFile\">\n <button type=\"submit\" onclick=\"uploadfile()\">\n Click to send the files\n </button>-->\n <input type=\"file\" id=\"myFile\" webkitdirectory directory multiple onchange=\"uploadfile()\">\n <br><br><br>\n <md-button ng-click=\"send({input:action()})\">\n Click to send the files\n </md-button>\n <hr>\n <textarea style=\"width:500px;height: 400px\" id=\"output\"></textarea>\n\n <script>\n \n function uploadfile(){\n var output = document.getElementById(\"output\");\n let files = document.querySelector('input[type=file]').files;\n var listsize = files.length;\n console.log(files);\n var chunk_size = 2000;\n var contentarray = [];\n //var offset = 0;\n \n \n var fullsize = 0;\n var c = 0 ;\n while(c < listsize){\n fullsize += files[c].size;\n c += 1;\n }\n var comp = 0;\n while(comp < listsize){\n \n // console.log(files[comp]);\n var offset = 0;\n if (files[comp].size > 0) {\n \n var myFile = files[comp];\n var size = myFile.size; //getting the file size so that we can use it for loop statement\n var i=0;\n console.log(\"file size \",size);\n while( i<size){\n var reader = new FileReader();\n var blob = myFile.slice(offset, offset + chunk_size); //slice the file by specifying the index(chunk size)\n var s = 0;\n //console.log(blob);\n reader.addEventListener('load', function (e) {\n \n res += btoa(e.target.result);//concatenate the output on each iteration.\n s += e.loaded;\n // console.log(\"s======\",s);\n // console.log(\"////////////////////////////////////////////////\",fullsize - s == fullsize - myFile.size);\n if (s % 2000 != 0){\n // console.log(\"hi\");\n // console.log(s);\n res += btoa(e.target.result);\n contentarray.push(res);\n s = 0;\n res = '';\n //console.log(contentarray);\n }\n \n \n // console.log(offset);\n \n // console.log(res);\n });\n reader.readAsBinaryString(blob);\n offset += chunk_size; // Increment the index position(chunk) \n i += chunk_size;\n // Keeping track of when to exit, by incrementing till we reach file size(end of file).\n }\n \n }\n // res = res.replace('undefined','');\n reader.addEventListener('loadend',function (e) {\n //res = res.replace('undefined','');\n console.log(contentarray);\n });\n console.log(\" ***************************************************************** \",comp);\n comp ++;\n var res='';\n \n }\n // msg.content = contentarray;\n }\n\n\n </script>\n</body>\n</html>\n \n",
        "storeOutMessages": true,
        "fwdInMessages": true,
        "resendOnRefresh": false,
        "templateScope": "local",
        "className": "",
        "x": 300,
        "y": 300,
        "wires": [
            [
                "ae07764595b20bdf"
            ]
        ]
    },
    {
        "id": "ba4cd6c4f1b1c4ad",
        "type": "ui_group",
        "name": "Default",
        "tab": "8e403f6af717befd",
        "order": 1,
        "disp": true,
        "width": 20,
        "collapse": false,
        "className": ""
    },
    {
        "id": "8e403f6af717befd",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

```

here is my code if it helps, i want to return the value of the content array to the next node

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 15:35 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/8 "2021-12-06T15:35:24Z")

</div>

You can't send messages from the browser code like that, as the code is running in the browser environment, not in the node-red server.

This might be helpful

> **[Node-RED Dashboard Template Examples (AngularJS)](https://it.knightnet.org.uk/kb/nr-qa/dashboard-template-examples/#a-couple-of-ways-to-send-a-msg-back-to-node-red)**
>
> Some examples of using AngularJS with the Node-RED Dashboard.
> Not all features of Angular are accessible via the Dashboard.

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 15:37 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/9 "2021-12-06T15:37:55Z")

</div>

Thank you so much for the help

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 15:39 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/10 "2021-12-06T15:39:57Z")

</div>

Could you describe what you are trying to achieve? I suspect that there may be much easier ways, it is easy as a beginner to go off down the wrong path because you do not know what can be done.

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 15:44 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/11 "2021-12-06T15:44:34Z")

</div>

I am reading a list of files from an input the files are of big sizes that's why am splitting them and then i have to encode them and send them one by one to a http request that has an encoded file as a body

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 15:53 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/12 "2021-12-06T15:53:30Z")

</div>

Why are you doing any of that inside a ui\_template node?

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 15:54 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/13 "2021-12-06T15:54:41Z")

</div>

because i need an input

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 15:54 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/14 "2021-12-06T15:54:59Z")

</div>

What sort of input?

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 15:57 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/15 "2021-12-06T15:57:25Z")

</div>

input file to choose the files

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 16:13 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/16 "2021-12-06T16:13:26Z")

</div>

Do you mean the user enters a file name?

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 16:15 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/17 "2021-12-06T16:15:57Z")

</div>

yes to choose a file from your local device

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 16:17 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/18 "2021-12-06T16:17:22Z")

</div>

Please give more information, it is hard work trying to understand. What do you want to show on the dashboard and what does the user do? Select from a dropdown list for example?

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 16:20 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/19 "2021-12-06T16:20:46Z")

</div>

choose a file or multiple files from the device they are .jt files then encode its content to b64 and then send it to the body of a http request

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [6 December 2021 16:24 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/20 "2021-12-06T16:24:41Z")

</div>

Where are the files? On the node-red server or on the machine running the browser?

---

<div class="post-metadata">

### Author: ![hanine](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@hanine](https://discourse.nodered.org/u/hanine)
#### Post date: [6 December 2021 16:27 UTC](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780/21 "2021-12-06T16:27:40Z")

</div>

my machine which is running the node red browser

[Next page](https://discourse.nodered.org/t/how-can-i-use-the-value-of-a-variable-i-created-inside-the-template-node/54780.md?page=2)
