# \[NODE\]implementation of mustache templates in external files

**URL:** <https://discourse.nodered.org/t/node-implementation-of-mustache-templates-in-external-files/67556>\
**Category:** Share Your Nodes\
**Created:** [10 September 2022 15:52 UTC](https://discourse.nodered.org/t/node-implementation-of-mustache-templates-in-external-files/67556 "2022-09-10T15:52:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![vitormnm](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vitormnm/32/52166_2.png) [@vitormnm](https://discourse.nodered.org/u/vitormnm)\
**Post date:** [10 September 2022 15:52 UTC](https://discourse.nodered.org/t/node-implementation-of-mustache-templates-in-external-files/67556/1 "2022-09-10T15:52:27Z")

</div>

hello everyone! I'm developing a node to implement mustache template in external files.  
So there is no need to deploy for changes to multiple templates.  
This node was thought soon after an implementation of a project in node-red where many TEMPLATE nodes were used to create dynamic HTML pages.  
Initial example:

- flow:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/b/ab469795e37e7f3c6d7f92c7829f945f611033ac.png)

- file directory:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/e/6eebac4e1b538a3b790c260cc5ac0ff5b478c91b.png)

- template file:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/851685df01b8b2eb4855f61bd4902de1eb6eda70.png)

- msg send

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/ed0675fa195c0c70534bcf104bdeb0200725128b.png)

- result html:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/ad03bffb8f4e76a5784361e2dc09a5a1828c7418.png)

Suggestions are always welcome!

---

<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:** [10 September 2022 19:49 UTC](https://discourse.nodered.org/t/node-implementation-of-mustache-templates-in-external-files/67556/2 "2022-09-10T19:49:16Z")

</div>

Hi. We always appreciate contributions. It make for a great ecosystem.

However, not meaning to rain on your parade, but what advantage does this contrib node have over the built in file node + template node?

Maybe if there were some extra features that made it worth while like outputting the rendered string to a user defined property? Like providing the file name from a user defined `msg` property or a context/ env variable? Or have additional properties in the output message to help users understand why certain tokens were/were not replaced? Perhaps if it had options to replace tokens that weren't found in the payload or env or context with a user defined default value (e.g. "NO VALUE")? Maybe you could support the (better/more features) handlebars library instead of mustache?

As it stands, I probably wouldn't use this node as (as far as I can see) offers little advantage over the built-in file+template node.

I hope you can extract the positive constructive feedback from my ramblings.

Thanks either way.

---

<div class="post-metadata">

**Author:** ![Stwissel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stwissel/32/126_2.png) [@Stwissel](https://discourse.nodered.org/u/Stwissel)\
**Post date:** [13 October 2023 05:03 UTC](https://discourse.nodered.org/t/node-implementation-of-mustache-templates-in-external-files/67556/3 "2023-10-13T05:03:29Z")

</div>

The big advantage here is template composition. In Mustache you could do {{\> file.name}} and a block of code gets included in your template. Invaluable for DRY.  
The template node has no base directory to look for the snippets. Especially for generating html composition makes sense

---

<div class="post-metadata">

**Author:** ![Stwissel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stwissel/32/126_2.png) [@Stwissel](https://discourse.nodered.org/u/Stwissel)\
**Post date:** [13 October 2023 05:12 UTC](https://discourse.nodered.org/t/node-implementation-of-mustache-templates-in-external-files/67556/4 "2023-10-13T05:12:26Z")

</div>

I would propose the following enhancements:

- add a configuration node that provides the mustache base directory. So multiple mustache nodes can share it
- add a drop-down that lists the file names available in that dir, so users can pick
- add a parameter to msg e.g. msg.templateName to be able to overwrite the preconfigured template

Happy to help if you need a hand implementing

---

<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:** [14 October 2023 14:13 UTC](https://discourse.nodered.org/t/node-implementation-of-mustache-templates-in-external-files/67556/5 "2023-10-14T14:13:32Z")

</div>

Sorry, I missed this earlier. Just to say that this would be easy enough to do with UIBUILDER without the need for another custom node.

And if you can do without mustache and use EJS instead, then UIBUILDER already allows this with a simple switch in settings.js

[EJS -- Embedded JavaScript templates](https://ejs.co/)
