@ralphwetzel/node-red-contrib-eta 2.0.0
A node to utilize Eta - the lightweight, powerful, pluggable embedded JS template engine.
@ralphwetzel/node-red-contrib-eta
A Node-RED node to utilize Eta - the lightweight, powerful, pluggable embedded JS template engine.
Changelog
v2.0.0
- v2 updates
eta.js
library to version v3.x - that introduced async rendering of templates. - Accessing data to be used for rendering was simplified, as
msg
was introduced as an alternative forit
. This allows to follow the Node-RED style way accessing data e.g. asmsg.payload
within templates:Be advised that there's an implementation detail that might break your
__root__
template!: In v1, rendering data used to be provided to the root template asit.msg
. Due to the mentioned change, it's now justmsg
.An example: Accessing the
payload
property (v1:it.msg.payload
) is now done simply viamsg.payload
.To feed data to partials, just forward the data object, e.g.
msg
:include(template_name, msg)
Inputs
msg
(object) : (standard) message object with data to be used for rendering the __root__ template.
Outputs
payload
(string) : the result of rendering the __root__ template with the data provided as input.
Details
This nodes allows to render a document template (named __root__) by utilizing the Eta JS template engine. For help regarding the template syntax refer to the Eta Syntax Overview website.
If you've enabled the use of the Monaco text editor, syntax highlighting support is provided.
The document template (__root__) shall be defined in the configuration options of this node.
Data provided to the node may be accessed in the template via a variable called msg
.
<% /*
This is the Eta root template.
You may add further templates to define
partials or layouts.
Check https://eta.js.org for syntax
support.
*/ -%>
<% = msg.payload + "! Wow!" %>
To use partials, you may define additional templates in the configuration options of this node.
Using those partials follows the standard Eta scheme; the data (object) again may be accessed - within the partial - via msg
.
<%~ include(template_name, msg) %>
Please be aware that file partials are not supported!
An example:
The __root__ document template:
The template of the partial - to be included:
You may import this example as well via the Node-RED Import menu option.