Skip to content

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.

<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):

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

{% 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:

{% 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):

{% 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:

{% 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.