Skip to main content

Html Template

Creates a dynamic HTML template

Common Properties

  • Name - The custom name of the node.
  • Color - The custom color of the node.
  • Delay Before (sec) - Waits in seconds before executing the node.
  • Delay After (sec) - Waits in seconds after executing node.
  • Continue On Error - Automation will continue regardless of any error. The default value is false.
info

if ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.

Output

  • Output - The rendered output of the HTML

Example HTML

<html>
<head>
<title>Title</title>
</head>
<body>
{{content}}
</body>
</html>

In the HTML template example above, the {{content}} is replaced by the value of msg.content.

How It Works

The HTML Template node uses Mustache templating to generate dynamic HTML content:

  1. Template Definition:

    • The HTML template is defined in the node's function/template field
    • Template can contain static HTML and dynamic placeholders using Mustache syntax
  2. Data Binding:

    • The entire message object is passed to the template engine
    • Any property in the message can be accessed using {{propertyName}} syntax
  3. Rendering:

    • Mustache engine processes the template
    • Replaces all placeholders with corresponding values from the message
    • Generates the final rendered HTML string
  4. Output:

    • The rendered HTML is stored in the output variable
    • Can be used in HTTP responses, saved to files, or sent via email

Requirements

  • Template: Valid HTML with Mustache placeholders
  • Message Data: Properties referenced in template must exist in the message object
  • Mustache Syntax: Follow Mustache templating syntax for placeholders

Error Handling

Error CodeDescriptionSolution
Core.Net.HttpTemplate.ErrOnCreateConfiguration parsing failed during node creationCheck node configuration in the flow
Core.Net.HttpTemplate.OnMessageMessage parsing errorVerify message format is valid JSON
Core.Net.HttpTemplate.ErrRenderTemplate rendering failedCheck template syntax and ensure referenced variables exist
Core.Net.HttpTemplate.OutputMarshalFailed to serialize outputCheck output variable configuration

Usage Examples

Example 1: Simple Variable Replacement

// Template in node:
// <h1>Hello {{name}}!</h1>
// <p>Your email is {{email}}</p>

msg.name = "John Doe";
msg.email = "john@example.com";
// After node execution:
// msg.output contains:
// <h1>Hello John Doe!</h1>
// <p>Your email is john@example.com</p>

Example 2: Email Template with Conditional Content

// Template in node:
// <html>
// <body>
// <h1>Order Confirmation</h1>
// <p>Order #{{orderNumber}}</p>
// {{#isPremium}}
// <p>Thank you for being a premium customer!</p>
// {{/isPremium}}
// </body>
// </html>

msg.orderNumber = "12345";
msg.isPremium = true;
// After node execution:
// msg.rendered contains full HTML with premium message included

Example 3: Loop Through Items

// Template in node:
// <ul>
// {{#items}}
// <li>{{name}}: ${{price}}</li>
// {{/items}}
// </ul>

msg.items = [
{name: "Product A", price: "29.99"},
{name: "Product B", price: "49.99"}
];
// After node execution:
// msg.html contains list items for each product

Usage Notes

  • Mustache Syntax: Uses standard Mustache templating ({{variable}}, {{#section}}, {{^inverted}}, etc.)
  • Nested Properties: Access nested object properties with dot notation: {{user.address.city}}
  • HTML Escaping: By default, HTML characters are escaped; use triple braces {{{raw}}} for unescaped HTML
  • Conditionals: Use {{#variable}}...{{/variable}} for conditional sections
  • Loops: Arrays are automatically iterated using the same conditional syntax
  • Comments: Use {{! This is a comment }} for template comments
  • Missing Variables: Missing variables render as empty strings (no error thrown)
  • Type Conversion: All values are converted to strings during rendering

Tips

  • Test templates with sample data before deploying to production
  • Use descriptive variable names in templates for better readability
  • Organize complex templates with proper HTML formatting and indentation
  • Store large templates in separate files and load them dynamically
  • Use conditionals to handle optional content gracefully
  • Validate output HTML to ensure it's well-formed
  • Combine with HTTP Out node to serve dynamic web pages
  • Use with Email nodes to send formatted HTML emails
  • Consider security: sanitize user input before including in templates
  • Cache rendered templates if the same data is used multiple times
  • HTTP Out - Send rendered HTML as HTTP response
  • HTTP In - Receive data to populate templates
  • Email - Send rendered HTML via email
  • File Operations - Save rendered HTML to files
  • String Operations - Manipulate template strings before rendering