# Template Inheritance

ADX supports Jinja's template inheritance features, allowing you to reuse and extend template definitions. The templates are referenced by their keys defined in **Templates and Assets → ADX Templates**.

## Include

The `{% include %}` tag allows you to include the content of another template within the current template.

```markup
<adx>
  <body>
    {% include "header_template" %}
    <text>Main content here</text>
    {% include "footer_template" %}
  </body>
</adx>
```

## Extends

The `{% extends %}` tag enables template inheritance. A child template can extend a base template and override specific blocks.

**Base template (`base_layout`):**

```markup
<adx>
  <pageTemplates>
    <template id="letterhead" pageSize="A4">
      <text bottom="280mm" left="20mm">Company Letterhead</text>
    </template>
  </pageTemplates>
  <body template="letterhead">
    {% block content %}{% endblock %}
  </body>
</adx>
```

**Child template:**

```markup
{% extends "base_layout" %}

{% block content %}
  <text>Specific document content here</text>
  <field title="Name">{{e.name}}</field>
{% endblock %}
```

Use `{{ super() }}` to render the parent block's content:

```markup
{% extends "base_layout" %}

{% block content %}
  {{ super() }}
  <text>Additional content after the parent content</text>
{% endblock %}
```

## Import

The `{% import %}` tag allows you to import macros and variables from another template.

**Helper template (`common_macros`):**

```markup
{% set copyright -%}
  <text fontSize="8" align="center">© 2024 Atfinity AG. All rights reserved.</text>
{%- endset %}

{% macro address_block(entity) -%}
  <text>{{entity.name}}</text>
  <text>{{entity.street}}</text>
  <text>{{entity.zip}} {{entity.city}}</text>
{%- endmacro %}
```

**Using the template:**

```markup
{% import "common_macros" as common %}

<body>
  {{ common.address_block(e) }}
  <space />
  {{- common.copyright -}}
</body>
```

## Template Keys

All template references (`include`, `extends`, `import`) use the **key** defined in **Templates and Assets → ADX Templates**. These keys are unique identifiers for your template definitions.


---

# 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.atfinity.io/document-xml-adx/jinja-templating/template-inheritance.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.
