> For the complete documentation index, see [llms.txt](https://docs.marpledata.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.marpledata.com/docs/marple-insight/setup-and-configuration/data-connection/connection-configuration/templating.md).

# Templating

## Templating Language

We use [Jinja templating](https://jinja.palletsprojects.com/en/stable/) to construct dynamic queries, allowing flexible adjustments tailored to your data model.

Jinja allows:

* **Loops (`for`)** → Automate query generation for multiple signals.
* **Conditions (`if`)** → Add optional calculations dynamically.

For example, for retrieving cursor stats in ADX, we could use the following query:

```
{% for name, series in time_series -%}
{{series}}
| summarize
    min = min(toreal(value)),
    max = max(toreal(value)),
    mean = avg(toreal(value))
{% if extended %},
    median = percentile(toreal(value), 50),
    std = stdev(toreal(value))
{% endif %}
| extend name = '{{ name }}';
```

## Template Constants

Marple allows you to substitute variables in query templates using Jinja syntax.&#x20;

These variables fall into three categories: **constants**, **dataset filters**, and **query-specific variables**.

* **Constants** are predefined values that can be referenced in queries as `{{CONSTANT_NAME}}`. You can define these constants within the configuration.
* **Dataset filters** are determined by the filter signals in your dataset definition. For example, if `session` is part of the filter list, it can be used in queries as `{{dataset.session}}`.
* **Query-specific variables** are defined per query and vary based on its purpose. For instance, a time series query might use `{{timestamp_start}}` and `{{timestamp_stop}}` to define the time range.

This approach ensures dynamic and flexible queries that adapt to different datasets while maintaining clarity and efficiency.

<figure><img src="/files/kZGNaTbVKSZmD93KpwWr" alt=""><figcaption></figcaption></figure>
