Nodes

Text Template#

The Text Template node allows you to create dynamic text output using the Handlebars templating language. It is useful for generating customized text based on input data, such as personalizing emails, creating dynamic web pages, or formatting data for reports.

Inputs#

The Text Template node accepts any number of inputs, which can be added dynamically. Each input represents a variable that can be used within the Handlebars template. The supported input types are:

  • String
  • Array
  • Boolean
  • Integer

Outputs#

  • result (String): The rendered text output after applying the Handlebars template to the input data.

Configuration#

  • textEditorData (String): The Handlebars template code. Use this to define the structure and content of the output text, inserting variables from the inputs.

  • textEditorOptions (Object): Options for the text editor used to write the Handlebars code. The default options are:

    {
      "options": {
        "language": "handlebars",
        "name": "Text template"
      }
    }
  • socketInputs (Array): An array defining the input sockets for the node. Each element represents an input variable that can be used in the Handlebars template. By default, this is an empty array and inputs can be added manually in the node editor.

Usage#

  1. Add the Text Template node to your spell.
  2. Connect one or more input nodes to the Text Template node. These will provide the dynamic data for the template.
  3. In the node editor, write your Handlebars template in the textEditorData field. Use the double curly brace syntax to insert variables, e.g. {{variableName}}.
  4. Connect the result output to the next node in your spell.
  5. Run the spell. The Text Template node will render the template with the provided input data and pass the resulting text to the next node.

Example#

Suppose you have a CSV file with user data and you want to generate a personalized email for each user. You could use the Text Template node like this:

  1. Use a Read CSV node to read the user data from a file. Connect its output to the Text Template node.
  2. In the Text Template node, write a Handlebars template for the email body:
Dear {{firstName}} {{lastName}},
 
Thank you for signing up for our service! Your username is {{username}}.
 
Best regards,
The Team
  1. Connect the result output to a Send Email node to send each personalized email.

Best Practices#

  • Keep your templates concise and focused. If a template gets too large or complex, consider breaking it into smaller sub-templates.
  • Use descriptive names for your input variables to make the template code more readable.
  • Take advantage of Handlebars features like conditionals and loops to create more dynamic templates.
  • Remember that Handlebars escapes HTML by default for security. If you need to render HTML tags from variables, use the triple curly brace syntax: {{{variable}}}.

Common Issues#

  • Forgetting to provide a value for a template variable will render the variable name as a literal in the output text. Make sure all variables used in the template have a corresponding input.
  • Handlebars syntax errors will cause the template rendering to fail. Double-check your curly braces and variable names.
  • Rendering user-provided data can be a security risk if not handled properly. Be cautious when rendering HTML input to avoid cross-site scripting vulnerabilities.