> For the complete documentation index, see [llms.txt](https://docs.atfinity.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.atfinity.io/document-xml-adx/jinja-templating/template-inheritance.md).

# 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.atfinity.io/document-xml-adx/jinja-templating/template-inheritance.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
