# 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>


---

# 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://docs.marpledata.com/docs/marple-insight/setup-and-configuration/data-connection/connection-configuration/templating.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.
