---
title: Template Syntax
slug: template-syntax
docTags: 
createdAt: 2021-07-21T15:07:34.000Z
---

:::hint{type="info"}
## Target Audience

The target audience of this document are developers or persons with at least some software development experience.&#x20;
:::

## Template Engine

We are using [Pebble Templates](https://pebbletemplates.io/) to populate email and document templates with data. Please be aware that we are still using version 3.0.4 of Pebble Templattes, because some of our custom extions are not yet compatible with the latest version of Pebble.

## Important Blocks

### Loops

```none
{% for offer in offers %}
{% endfor %}
```

### If Blocks

```none
{% if test == 'teststring' %}
{% elseif test == 'asdf' %}
{% else %}
{% endif %}
```

## Important Modifiers

### trim

```none
{{ "   mein text    " | trim }}
```

### numberformat

By default a decimal point number will be printed with maximum precission - in some cases you might want to use a custom format.

**Formatting a number as integer**

```none
{{ item.itemCount | numberformat('#') }}
```

**Formatting a number with exactly two decimal points and a local specific thousand separator**

```none
{{ item.itemCount | numberformat('#,##0.00') }}
```

### nl2br

Sometimes you might encounter a multi-line string, where the lines are separated by a newline-character. When you want to render such a string within an HTML template (keeping the line breaks) you have to convert the newline characters to HTML br (line break) elements.

```none

 {{ address | nl2br }}
```

## Custom Macros

### Gender specific text

```none
{{greeting(guest.gender, 'Hallo Herr', 'Hallo Frau', 'Hallo')}} {{ guest.lastName}}
```

### Currency format

```none
{{money(offer.unitPriceSummary.amount, offer.unitPriceSummary.currency)}}
```

## Custom Extensions

In certain situations the WYIWYG template editor would remove (or complain about) invalid markup - e.g. when wrapping loops or if conditions around table cells or table rows. In such cases you can add the for or if condition directly onto the HTML element as an attribute.

### h-for Attribute

```none
<tr h-for="item in offer.shoppingCart">
    <td>{{ item.itemCount | numberformat("#") }} x {{ item.inHouseService.name.$locale }}</td>
    <td>{{ money(item.unitPriceSummary.amount + item.unitPriceSummary.excludedTaxAmount, item.unitPriceSummary.currency) }}</td>
</tr>
```

### h-if

```none

<div h-if="address != null">
    {{ address }}
</div>
```

