2018-11-30 13:50:49 +01:00
|
|
|
<!--
|
|
|
|
Copyright JS Foundation and other contributors, http://js.foundation
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
|
|
|
|
2020-01-15 03:40:48 +01:00
|
|
|
<script type="text/html" data-help-name="template">
|
2018-11-30 13:50:49 +01:00
|
|
|
<p>Sets a property based on the provided template.</p>
|
|
|
|
<h3>Inputs</h3>
|
|
|
|
<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>
|
2022-01-07 18:43:53 +01:00
|
|
|
<dd>A template to be populated from <code>msg.payload</code>. If not configured in the edit panel,
|
2018-11-30 13:50:49 +01:00
|
|
|
this can be set as a property of msg.</dd>
|
|
|
|
</dl>
|
|
|
|
<h3>Outputs</h3>
|
|
|
|
<dl class="message-properties">
|
|
|
|
<dt>msg <span class="property-type">object</span></dt>
|
|
|
|
<dd>a msg with a property set by populating the configured template with properties from the incoming msg.</dd>
|
|
|
|
</dl>
|
|
|
|
<h3>Details</h3>
|
|
|
|
<p>By default this uses the <i><a href="http://mustache.github.io/mustache.5.html" target="_blank">mustache</a></i>
|
|
|
|
format, but this can be switched off if required.</p>
|
|
|
|
<p>For example, when a template of:
|
|
|
|
<pre>Hello {{payload.name}}. Today is {{date}}</pre>
|
|
|
|
<p>receives a message containing:
|
|
|
|
<pre>{
|
2019-10-10 11:34:10 +02:00
|
|
|
date: "Monday",
|
2018-11-30 13:50:49 +01:00
|
|
|
payload: {
|
2019-10-09 09:41:33 +02:00
|
|
|
name: "Fred"
|
2018-11-30 13:50:49 +01:00
|
|
|
}
|
|
|
|
}</pre>
|
|
|
|
<p>The resulting property will be:
|
|
|
|
<pre>Hello Fred. Today is Monday</pre>
|
|
|
|
<p>It is possible to use a property from the flow context or global context. Just use <code>{{flow.name}}</code> or
|
|
|
|
<code>{{global.name}}</code>, or for persistable store <code>store</code> use <code>{{flow[store].name}}</code> or
|
|
|
|
<code>{{global[store].name}}</code>.
|
2019-09-20 12:20:40 +02:00
|
|
|
<p><b>Note: </b>By default, <i>mustache</i> will escape any non-alphanumeric or HTML entities in the values it substitutes.
|
2021-08-12 17:41:32 +02:00
|
|
|
To prevent this, use <code>{{{triple}}}</code> braces.</p>
|
2021-08-31 17:59:32 +02:00
|
|
|
<p>If you need to use <code>{{ }}</code> within your content, you can change the characters
|
|
|
|
used to mark the templated sections. For example, to use <code>[[ ]]</code>
|
|
|
|
instead, add the following line to the top of the template:</p>
|
|
|
|
<pre>{{=[[ ]]=}}</pre>
|
2022-09-13 15:08:22 +02:00
|
|
|
<h4>Using environment variables</h4>
|
|
|
|
<p>The template node can access environment variables using the syntax:</p>
|
|
|
|
<pre>My favourite colour is {{env.COLOUR}}.</pre>
|
2018-11-30 13:50:49 +01:00
|
|
|
</script>
|