# Twig templating in Eliona

## **Introduction to Twig Templating**

Eliona uses [-> \[External Link\] Twig](https://twig.symfony.com/), a powerful and flexible templating engine for JavaScript and PHP, for the dynamic generation of message content. Twig makes it possible to define templates that are used by external messaging services such as SMS, Google Chat, Slack, or email.

### **Twig.js Version**

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

* [-> \[External Link\] Twig.js Repository](https://github.com/twigjs/twig.js)
* [-> \[External Link\] Twig.js Implementation Notes](https://github.com/twigjs/twig.js/wiki/Implementation-Notes)

***

## Twig Syntax and Functions

Twig syntax makes it possible to insert and process dynamic content in templates. Some commonly used functions are:

### **Output variables**

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

### **Use conditions**

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

### **Use loops**

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

### **Format strings**

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

***

## **Available Templates and Variables in Eliona**

Eliona offers various template types for different use cases:

* [**Ticket Template**](#ticket-template)
* [**Alarm Template**](#alarm-template)
* [**Password Reset Template**](#passwort-reset-template)
* [**yAxis Formatter Template**](#yaxis-formatter)
* [**Legend Template**](#legend-template)

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 to automatically generate ticket notifications. The following variables are available:

```json
{
  "ticket": {
    "ticket_id": "Unique ID of the ticket",
    "parent_id": "ID of the parent ticket, if present",
    "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": "Creation time of the ticket",
    "assigned_to": "Assigned person or group",
    "assigned_at": "Time of assignment",
    "closed_at": "Time of closure",
    "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 modification",
    "contact": "Contact information",
    "tags": "List of tags associated with the ticket"
  }
}
```

### **Example of a Ticket Template**

```twig
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 dataset and contains extensive details about alarms and their associated assets.

```json
{
  "alarm": {
    "low": "Lower limit",
    "high": "Upper limit",
    "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": "Alarm subject",
    "subtype": "Alarm subtype",
    "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": "Creation time of the alarm",
    "created_by": "Creator of the alarm",
    "auto_ticket": "Indicates whether a ticket is created automatically",
    "modified_at": "Time of last modification",
    "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 when 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 the asset's tags",
    "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**

```twig
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**

```json
"user": {
  "email": "User's email address",
  "user_id": "Unique user ID",
  "lastname": "User's last name",
  "firstname": "User's first name",
  "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**

```twig
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.

```json
{
    "host": "Domain of the environment where the system is operated",
    "password_reset_token": "Unique token for resetting the password"
}
```

### **Example of a Password Reset Template**

```twig
Hello,  

to reset your password, please click 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 preserve functionality:  
href="https://{{ host }}/password-reset/{{ password_reset_token }}"
```

{% hint style="warning" %}
Make sure that the link remains unchanged to preserve functionality: href="https\://{{host}}/password-reset/{{password\_reset\_token}}"
{% endhint %}

***

## **yAxis Formatter**

The **yAxis Formatter** determines the display of the **axis label** in charts. It shows the current value of the data series together 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 aggregation
* `{{aggregatedDataRaster}}` – Grid with which the data was aggregated
* `{{aggregatedDataType}}` – Type of aggregation (e.g. average, sum)

### **Example of a yAxis formatter**

```twig
twigCopyEdit{{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 aggregation
* `{{aggregatedDataRaster}}` – Grid with which the data was aggregated
* `{{aggregatedDataType}}` – Type of aggregation (e.g. average, sum)

### **Example of a legend template**

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

**Result for a temperature sensor:**\
→ `Air conditioner office 1 - room temperature (°C)`

***

## **Conclusion**

Twig.js enables 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 about the Twig syntax is available in the official documentation: [-> \[External Link\] Twig.js Wiki](https://github.com/twigjs/twig.js/wiki/Implementation-Notes).
