# Feature request: ability to inject node templates dynamically

**URL:** <https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742>\
**Category:** Feature Requests\
**Created:** [16 January 2023 05:05 UTC](https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742 "2023-01-16T05:05:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [16 January 2023 05:05 UTC](https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742/1 "2023-01-16T05:05:30Z")

</div>

I'd like to be able to write "node templates", i.e., the code for a node that lives in the flow editor, using Vue. I have it all working pretty nicely and rather simply and cleanly. The one stumbling block is that there is no clean way to inject the node template that I generate into the process that collects all the templates and preps them for sending to the flow editor. (And this path is the only clean way to get that stuff to the flow editor.)

I'm not 100% sure on the best way to provide an API call for this. Right now, by hook & crook, I call `RED.registry.getFullNodeInfo` and set the `config` and `help` fields. Having some call to set these cleanly would do the trick. (But I've been focused on how to work around this, not on exactly what and how to cleanly expose.)

Is there any appetite to facilitate this?

---

<div class="post-metadata">

**Author:** ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)\
**Post date:** [17 January 2023 01:35 UTC](https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742/2 "2023-01-17T01:35:49Z")

</div>

It occurred to me today that a clean way to integrate this from an API point of view would be to add an `options` parameter to RED.nodes.registerType. E.g., to inject script, template, and help one would use something like:

```auto
RED.nodes.registerType("my node", myNode, { script, template, help })

```

I haven't looked at what it would take to propagate the option values within Node-RED, but it seems like a pretty clean addition to the existing API.

---

<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:** [17 January 2023 10:19 UTC](https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742/3 "2023-01-17T10:19:42Z")

</div>

Hi @tve

I think you're on the right track here:

```auto
RED.nodes.registerType("my node", myNode, { script, template, help })

```

The devil will be in the detail, but this would be the cleanest API to start with.

As you know from digging through the code, the node loading logic has evolved over time and its a bit tangled, but this ought to be the right way to inject pieces into the node definition.

---

<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:** [17 January 2023 12:27 UTC](https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742/4 "2023-01-17T12:27:25Z")

</div>

> [@knolleary](#):
>
> `RED.nodes.registerType("my node", myNode, { script, template, help })`

That might be quite limiting if you ever wanted to do further extensions later. Would it be better to do something like:

`RED.nodes.registerType("my node", myNode, { nodeTemplate: { script, template, help } })`

That way, you could further enhance the options in the future without fear of backwards compatibility. It also makes it clearer in the code what the data is for.

---

<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:** [17 January 2023 12:33 UTC](https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742/5 "2023-01-17T12:33:43Z")

</div>

As I said, the devil will be in the detail.

The principle of using the existing options object to provide the additional details is good. What we call those additional properties can be bike shedded all day long 🙂

---

<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:** [18 March 2023 12:33 UTC](https://discourse.nodered.org/t/feature-request-ability-to-inject-node-templates-dynamically/73742/6 "2023-03-18T12:33:58Z")

</div>

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