Twig Templating in Eliona

Introduction to Twig Templating

Eliona uses -> [External Link] Twig, a powerful and flexible templating engine for JavaScript and PHP, for the dynamic generation of message content. Twig allows you to define templates that are used by external messaging services such as SMS, Google Chat, Slack, or email.

Twig.js Version

The current implemented version of Twig.js in Eliona is 1.17.1. The full documentation and implementation notes are available at the following links:


Twig Syntax and Functions

Twig syntax allows you to insert and process dynamic content in templates. Some frequently used functions are:

Outputting Variables

{{ alarm.val }}  {# Outputs the value of the alarm #}
{{ asset.name }}  {# Displays the name of the affected asset #}

Using Conditions

{% if alarm.prio == 1 %}
    Attention: High priority!
{% else %}
    Normal alarm.
{% endif %}

Using Loops

{% for tag in alarm.tags %}
    - {{ tag }}
{% endfor %}

Formatting Strings

{{ alarm.message.come.de | upper }}  {# Outputs the alarm text in uppercase #}

Available Templates and Variables in Eliona

Eliona offers different template types for various use cases:

Each of these templates supports specific variables that are dynamically populated with the respective data.


Ticket Template

Available Variables

The ticket template can be used for the automated generation of ticket notifications. The following variables are available:

{
  "ticket": {
    "ticket_id": "Unique ID of the ticket",
    "parent_id": "ID of the parent ticket, if available",
    "title": "Title of the ticket",
    "description": "Description of the ticket",
    "priority": "Priority of the ticket",
    "reason": "Reason or cause of the ticket",
    "state": "Current status of the ticket",
    "created_by": "Creator of the ticket",
    "created_at": "Time of ticket creation",
    "assigned_to": "Assigned person or group",
    "assigned_at": "Time of assignment",
    "closed_at": "Time of closing",
    "proj_id": "Project ID",
    "asset_id": "Asset ID",
    "alarm_id": "Alarm ID, if linked to an alarm",
    "alarm": "Details of the linked alarm",
    "modified_by": "Last editor",
    "modified_at": "Time of last change",
    "contact": "Contact information",
    "tags": "List of tags associated with the ticket"
  }
}

Example of a Ticket Template

New Ticket: {{ ticket.title }}

Message:
Ticket ID: {{ ticket.ticket_id }}
Created by: {{ ticket.created_by }}
Priority: {{ ticket.priority }}
Description: {{ ticket.description }}

Alarm Template

Available Variables

The alarm template is based on a test data set and contains extensive details about alarms and their associated assets.

{
  "alarm": {
    "low": "Lower limit value",
    "high": "Upper limit value",
    "tags": "List of tags associated with the alarm",
    "prio": "Priority level of the alarm",
    "ack_p": "Indicates whether the alarm must be acknowledged",
    "equal": "Indicates whether an equality check is performed",
    "enable": "Activation status of the alarm",
    "urldoc": "Documentation URL",
    "func_id": "Functional ID of the alarm",
    "msg": "The resolved alarm message",
    "message": {
      "come": {
        "de": "{{asset.name}} ({{alarm.val}})",
        "en": "{{asset.name}} ({{alarm.val}})",
        "fr": "{{asset.name}} ({{alarm.val}})",
        "it": "{{asset.name}} ({{alarm.val}})"
      },
      "gone": "Message when the alarm ends"
    },
    "subject": "Subject of the alarm",
    "subtype": "Subtype of the alarm",
    "alarm_id": "Unique alarm ID",
    "asset_id": "ID of the affected asset",
    "attribute": "Affected attribute of the asset",
    "dont_mask": "Masking status of the alarm",
    "notify_on": "Notification trigger (e.g., 'R' for Reminder)",
    "check_type": "Type of alarm check",
    "created_at": "Time of alarm creation",
    "created_by": "Creator of the alarm",
    "auto_ticket": "Indicates whether a ticket is created automatically",
    "modified_at": "Time of last change",
    "modified_by": "Last editor",
    "ts": "Timestamp of the alarm",
    "val": "Value of the affected parameter",
    "multi": "Multiplier for the alarm value",
    "ack_ts": "Time of acknowledgment",
    "gone_ts": "Time the alarm disappeared",
    "ack_text": "Acknowledgment text",
    "ack_user_id": "ID of the acknowledging user"
  },
  "locale":"The language and region setting",
  "domain_name": "The domain name of the environment",
  "asset": {
    "ar": "Activation status",
    "gai": "Global Asset ID",
    "lat": "Latitude of the asset",
    "lon": "Longitude of the asset",
    "name": "Name of the asset",
    "tags": "List of tags of the asset",
    "expert": "Expert mode enabled",
    "storey": "Floor of the asset",
    "urldoc": "Documentation URL of the asset",
    "proj_id": "Project ID",
    "archived": "Archiving status",
    "asset_id": "Unique asset ID",
    "acl_access": "Access status",
    "asset_type": "Type of the asset",
    "tracker_id": "Tracker ID",
    "description": "Description of the asset",
    "acl_permissions": "Access permissions"
  }
}

Example of an Alarm Template

Alarm for {{ asset.name }}

Message:
The alarm "{{ alarm.message.come.de }}" was triggered.
Attribute: {{ alarm.attribute }}
Value: {{ alarm.val }}

User Template

The User Template allows access to user-specific information—especially for notification purposes (e.g., email, chat, or alarm forwarding). It can be used in all templates where user data is available.

Available Variables

"user": {
  "email": "Email address of the user",
  "user_id": "Unique user ID",
  "lastname": "Last name of the user",
  "firstname": "First name of the user",
  "google_chat": "Google Chat address (optional)",
  "slack": "Slack address (optional)",
  "mail2service": {
    "voice": "Email address for voice notifications (e.g., eCall Voice)",
    "sms": "Email address for SMS notifications (e.g., eCall SMS)"
  }
}

Example of a User Template

Notification to: {{ user.firstname }} {{ user.lastname }} ({{ user.email }})

Forward voice alarm to: {{ user.mail2service.voice }}
Forward SMS alarm to: {{ user.mail2service.sms }}

Slack user: {{ user.slack }}
Google Chat: {{ user.google_chat }}

Password Reset Template

Available Variables

The password reset template is used in Eliona to send users an email with a link to reset their password.

{
    "host": "Domain of the environment in which the system is operated",
    "password_reset_token": "Unique token for resetting the password"
}

Example of a Password Reset Template

Hello,

to reset your password, please click on the following link:

<a href="https://{{ host }}/password-reset/{{ password_reset_token }}">Reset password</a>

If you did not request this, you can ignore this email.

Make sure that the link remains unchanged to retain functionality:
href="https://{{ host }}/password-reset/{{ password_reset_token }}"

yAxis Formatter

The yAxis Formatter determines the display of the axis label in charts. It shows the current value of the data series along with additional attribute information.

Available Variables for the yAxis Formatter

  • {{unit}} – Unit of the value (e.g., °C, %, kWh)

  • {{value}} – The current value of the data series

  • {{attribute}} – Name of the attribute

  • {{gai}} – Global Asset ID

  • {{aggregatedDataField}} – Data field for the aggregation

  • {{aggregatedDataRaster}} – Raster with which the data was aggregated

  • {{aggregatedDataType}} – Type of aggregation (e.g., average, sum)

Example of a yAxis Formatter

{{value}} {{unit}} ({{attribute}})

Result for temperature data: → 22.5 °C (Room temperature)


Legend Template

The Legend Template determines the display of the legend label in charts. It describes the data series by combining the name of the asset or data series with attribute information.

Available Variables for the Legend Template

  • {{unit}} – Unit of the value (e.g., °C, %, kWh)

  • {{attribute}} – Name of the attribute

  • {{gai}} – Global Asset ID

  • {{name}} – Name of the asset or data series

  • {{aggregatedDataField}} – Data field for the aggregation

  • {{aggregatedDataRaster}} – Raster with which the data was aggregated

  • {{aggregatedDataType}} – Type of aggregation (e.g., average, sum)

Example of a Legend Template

{{name}} - {{attribute}} ({{unit}})

Result for a temperature sensor: → Air conditioner Office 1 - Room temperature (°C)


Conclusion

Twig.js enables a flexible and efficient use of templates in Eliona. By using Twig variables and functions, personalized content can be generated for tickets, alarms, and emails. More information on Twig syntax is available in the official documentation: -> [External Link] Twig.js Wiki.

Last updated