mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
enable template config via msg.template for stored or generated templates (#1503)
* updates to 80-template to allow setting template with msg.template * updated 80-template_spec test for msg.template support * fixed 80-template.js test
This commit is contained in:
committed by
Dave Conway-Jones
parent
3988a648d6
commit
f21c8154ed
@@ -54,6 +54,9 @@
|
||||
<dl class="message-properties">
|
||||
<dt>msg <span class="property-type">object</span></dt>
|
||||
<dd>A msg object containing information to populate the template.</dd>
|
||||
<dt class="optional">template <span class="property-type">string</span></dt>
|
||||
<dd>A template to be populated from msg.payload. If not configured in the edit panel,
|
||||
this can be set as a property of msg.</dd>
|
||||
</dl>
|
||||
<h3>Outputs</h3>
|
||||
<dl class="message-properties">
|
||||
|
@@ -83,6 +83,16 @@ module.exports = function(RED) {
|
||||
node.on("input", function(msg) {
|
||||
try {
|
||||
var value;
|
||||
/***
|
||||
* Allow template contents to be defined externally
|
||||
* through inbound msg.template IFF node.template empty
|
||||
*/
|
||||
if (msg.hasOwnProperty("template")) {
|
||||
if (node.template == "" || node.template === null) {
|
||||
node.template = msg.template;
|
||||
}
|
||||
}
|
||||
|
||||
if (node.syntax === "mustache") {
|
||||
if (node.outputFormat === "json") {
|
||||
value = mustache.render(node.template,new NodeContext(msg, node.context(), null, true));
|
||||
|
Reference in New Issue
Block a user