This Jinja2 extension adjusts the indentation of block content to a specified width.
python
>= 3.9
Install the latest release with pip:
pip install jinja2-indent
The {% indent %}
tag provided by this extension allows you to adjust the indentation level of the content inside the tag block. You can specify the desired width (in spaces), and the extension will reformat the content accordingly. This is particularly useful for aligning nested or indented structures in templates.
The following example demonstrates how to increase the indentation of a block of text:
root:
{% indent 2 %}
- name: a
value: 1
- name: b
value: 2
- name: c
value: 3
{% endindent %}
root:
- name: a
value: 1
- name: b
value: 2
- name: c
value: 3
The following example demonstrates how to remove unnecessary indentation from a block of text:
- name: a
value: 1
{% indent 0 %}
- name: b
value: 2
{% endindent %}
- name: c
value: 3
- name: a
value: 1
- name: b
value: 2
- name: c
value: 3