# Pass msg.name to a js variable in core template

**URL:** <https://discourse.nodered.org/t/pass-msg-name-to-a-js-variable-in-core-template/3501>\
**Category:** General\
**Created:** [27 September 2018 15:09 UTC](https://discourse.nodered.org/t/pass-msg-name-to-a-js-variable-in-core-template/3501 "2018-09-27T15:09:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkdim](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tkdim](https://discourse.nodered.org/u/tkdim)\
**Post date:** [27 September 2018 15:09 UTC](https://discourse.nodered.org/t/pass-msg-name-to-a-js-variable-in-core-template/3501/1 "2018-09-27T15:09:38Z")

</div>

I want to pass an array of objects from my flow to a js variable inside core template node and use them as input in a javascript program and it is not working.

my sample flow:

```auto
[{"id":"9f68c4b6.99ed08","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"deed6c6d.e34968","type":"http in","z":"9f68c4b6.99ed08","name":"","url":"/hello","method":"get","upload":false,"swaggerDoc":"","x":270,"y":125,"wires":[["e12e0103.c4f09"]]},{"id":"e12e0103.c4f09","type":"function","z":"9f68c4b6.99ed08","name":"function","func":"msg.mya = [{\"apples\":25.3,\"bananas\":25,\"oragnges\":0.1}];\n\nreturn msg;","outputs":1,"noerr":0,"x":435,"y":125,"wires":[["c0dea9ec.e6d348"]]},{"id":"c0dea9ec.e6d348","type":"template","z":"9f68c4b6.99ed08","name":"template","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<HTML>\n <HEAD>\n <TITLE>Title</TITLE>\n <script> var myValues ={{mya }}; </script>\n\n </HEAD>\n\n <BODY>\n <H1>This is a Header</H1>\n <H2>This is a Medium Header</H2>\n\n\n </BODY>\n\n</HTML> ","x":595,"y":125,"wires":[["a3bdb570.3f4d48"]]},{"id":"a3bdb570.3f4d48","type":"http response","z":"9f68c4b6.99ed08","name":"","statusCode":"","headers":{},"x":750,"y":125,"wires":[]}]

```

Thanks in advance

---

<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:** [27 September 2018 15:25 UTC](https://discourse.nodered.org/t/pass-msg-name-to-a-js-variable-in-core-template/3501/2 "2018-09-27T15:25:26Z")

</div>

Hi,

The mustache syntax used by the Template doesn't know how to write a whole objects into the template.

One way of achieving that would be to JSON encode the property first, so you have a String containing the object data and then inserting that.

Your function would be:

```auto
msg.mya = JSON.stringify([{"apples":25.3,"bananas":25,"oragnges":0.1}]);
return msg

```

---

<div class="post-metadata">

**Author:** ![tkdim](https://avatars.discourse-cdn.com/v4/letter/t/e19adc/32.png) [@tkdim](https://discourse.nodered.org/u/tkdim)\
**Post date:** [27 September 2018 15:45 UTC](https://discourse.nodered.org/t/pass-msg-name-to-a-js-variable-in-core-template/3501/3 "2018-09-27T15:45:46Z")

</div>

It worked!

Thank you very much for your instant reply
