@ralphwetzel/node-red-contrib-eta 2.0.0

A node to utilize Eta - the lightweight, powerful, pluggable embedded JS template engine.

npm install @ralphwetzel/node-red-contrib-eta

@ralphwetzel/node-red-contrib-eta

image

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 for it. This allows to follow the Node-RED style way accessing data e.g. as msg.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 as it.msg. Due to the mentioned change, it's now just msg.

      An example: Accessing the payload property (v1: it.msg.payload) is now done simply via msg.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:

eta_root

The template of the partial - to be included:

eta_partial

You may import this example as well via the Node-RED Import menu option.

References

Node Info

Version: 2.0.0
Updated 11 months, 3 weeks ago
License: MIT
Rating: 1.0 1

Categories

Actions

Rate:

Downloads

1 in the last week

Nodes

  • etaTemplate

Keywords

  • node-red
  • Eta
  • Template Engine
  • Javascript
  • template

Maintainers