# Populate html template from a file

**URL:** <https://discourse.nodered.org/t/populate-html-template-from-a-file/45937>\
**Category:** General\
**Created:** [19 May 2021 16:47 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937 "2021-05-19T16:47:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [19 May 2021 16:47 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/1 "2021-05-19T16:47:47Z")

</div>

I'm trying to load the `template` node with an incoming template from a file node.

When I pass the file payload to the template, I see mustache curly braces `{{ xyz }}` on the page.

If I take this same template code and copy it into the node `template` section... It works fine.

There is something about `msg.template`, I try to attach the code to this, but I don't get anything.

My goal is to remotely open and save the template file from my design tool [Pinegrow], and have node-red template open these templates without needing to manually copy and paste the code to the template node each time.

Is there something I'm missing?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [19 May 2021 17:17 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/2 "2021-05-19T17:17:05Z")

</div>

Probably easier to use the static folder feature (see settings.js). Read the file, replace any dynamic variables and write to the static folder.

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [19 May 2021 21:52 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/3 "2021-05-19T21:52:48Z")

</div>

👍 Thank you

So, Just to clarify...  
Passing `msg.template` [as a string of an html/mustache template] into the `template` node won't render as if it were placed in the `template` node's `Edit template node`'s code editor?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [20 May 2021 09:10 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/4 "2021-05-20T09:10:52Z")

</div>

I don't know the answer to that I'm afraid. I've never actually needed to try that. In fact, it hadn't even occurred to me 😀

But then I did write uibuilder so I use that when I want a web app 😉

---

<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:** [20 May 2021 09:31 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/5 "2021-05-20T09:31:30Z")

</div>

> [@mrSidX](#):
>
> Just to clarify...  
> Passing `msg.template` [as a string of an html/mustache template] into the `template` node won't render as if it were placed in the `template`

Incorrect.

The template node WILL render `msg.template`

The input `msg.template` is...  
`This is msg.topic >> {{topic}} << This is msg.payload >> {{payload}} << This is msg.test>> {{test}} <<`

The output is ...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/7591c6b4f90750e7d82e6b5b6fe7ddbd3fcc2cce.png)

  

Here is a demo...

```auto
[{"id":"9b5f87bc.872af8","type":"inject","z":"4b3f21a3.ba434","name":"","props":[{"p":"template","v":"This is msg.topic >> {{topic}} << This is msg.payload >> {{payload}} << This is msg.test>> {{test}} <<","vt":"str"},{"p":"payload"},{"p":"test","v":"HELLO FROM msg.test","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"HELLO FROM msg.topic","payload":"HELLO FROM msg.payload","payloadType":"str","x":740,"y":3160,"wires":[["c5155da0.d0176"]]},{"id":"c5155da0.d0176","type":"template","z":"4b3f21a3.ba434","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"","output":"str","x":950,"y":3160,"wires":[["7184f9ec.be18b8"]]},{"id":"7184f9ec.be18b8","type":"debug","z":"4b3f21a3.ba434","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1170,"y":3160,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [21 May 2021 19:16 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/6 "2021-05-21T19:16:49Z")

</div>

... I totally forget about your web builder. I need to revisit it. Was neato when I was looking at it a few times.

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [21 May 2021 19:43 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/7 "2021-05-21T19:43:43Z")

</div>

Thank you for verifying, I was able to double check this,  
and seems that I wasn't converting `msg.payload` to the `msg.template` ? Seems to be working now.

Thank again!

---

<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 July 2021 19:43 UTC](https://discourse.nodered.org/t/populate-html-template-from-a-file/45937/8 "2021-07-20T19:43:52Z")

</div>

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