# Render Engine

The `/Templates` endpoint renders templates in any format using the [*Apache FreeMarker®*](https://freemarker.apache.org/index.html).&#x20;

> *Apache FreeMarker® is a template engine: a library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data. Templates are written in the FreeMarker Template Language (FTL), which is a simple, specialized language... .*

<figure><img src="/files/N8J9JOiG4r91HOP9FoTq" alt=""><figcaption><p>How it works: FreeMarker</p></figcaption></figure>

Imagine you have any document that contains placeholders - which we call a **template**:

```ftl
Hello ${UserName}
Welcome to the Freemarker render engine.
```

And you have the data, which you want to insert into this template, to make it a document.&#x20;

```json
{
    "UserName" : "Markus Schmidt"
}
```

We call the process *to fill out the template:* **render** a template.

> **render( Template, Data) ⇒ document**

#### Example

```http
POST {{host}}/templates/render?templateName=...

{ "UserName" : "Markus Schmidt" }

--- response ---

Hello Markus Schmidt!
Welcome to the Freemarker render engine.
```

{% content-ref url="/pages/Q4X7XYPj6VUehbYvLn87" %}
[The Basics](/mspro.services/endpoints/render-engine/the-basics.md)
{% endcontent-ref %}

## Render Example

[*Apache FreeMarker®*](https://freemarker.apache.org/index.html) is a powerful and proven open source library to render documents. Here is a second, more complex example, about what to expect.

Imagine you want to send a formatted HTML e-mail in case of an error. Here's the *FreeMarker* template, containing placeholders:

```html
<h1>Error Details</h1>

<p>Execution Id : ${execId}<br/>
Trace Id : ${traceId}<br/>
Time-Stamp : ${dtUtc}</p>

<h2>Errors</h2>
<#list errors as err>
<p>Filename=${err.filename}<br/>
<b>RecId=${err.recordId}</b>: <i>${err.message}</i>
<p />
</#list>
```

In case of an exception you have the following dataset that you want to use to render a nice e-mail:

```json
{ 
    "execId" : "4711",
    "traceId" : "0AF7-D309",
    "dtUtc" : "2024-05-02T13:00:00.123",
    "errors" : [
        { "recordId" : 1000, "filename" : "File01.csv", "message" : "Missing zip-code."},
        { "recordId" : 2001, "filename" : "File02.csv", "message" : "Missing street."},
        { "recordId" : 2103, "filename" : "File02.csv", "message" : "Invalud amount."}
    ]
}
```

### The output

```markup
<h1>Error Details</h1>

<p>Execution Id : 4711<br/>
Trace Id : 0AF7-D309<br/>
Time-Stamp : 02.05.2024 13:00:00</p>

<h2>Errors</h2>
<p>Filename=File01.csv<br/>
<b>RecId=1000</b>: <i>Missing zip-code.</i>
<p />
<p>Filename=File02.csv<br/>
<b>RecId=2001</b>: <i>Missing street.</i>
<p />
<p>Filename=File02.csv<br/>
<b>RecId=2103</b>: <i>Invalud amount.</i>
<p />
```

<figure><img src="/files/Zg9vxy4CUkff3gLH7bFH" alt="" width="347"><figcaption><p>Rendered data in the browser</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://services.markusschmidt.pro/mspro.services/endpoints/render-engine.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
