Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dldevinc/jinja2-indent
A Jinja2 extension for managing indentation in templates.
https://github.com/dldevinc/jinja2-indent
Last synced: 12 days ago
JSON representation
A Jinja2 extension for managing indentation in templates.
- Host: GitHub
- URL: https://github.com/dldevinc/jinja2-indent
- Owner: dldevinc
- Created: 2024-12-13T17:20:07.000Z (28 days ago)
- Default Branch: main
- Last Pushed: 2024-12-13T17:31:16.000Z (28 days ago)
- Last Synced: 2024-12-13T18:30:38.245Z (28 days ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# jinja2-indent
This Jinja2 extension adjusts the indentation of block content to a specified width.
[![PyPI](https://img.shields.io/pypi/v/jinja2-indent.svg)](https://pypi.org/project/jinja2-indent/)
[![Build Status](https://github.com/dldevinc/jinja2-indent/actions/workflows/tests.yml/badge.svg)](https://github.com/dldevinc/jinja2-indent)
[![Software license](https://img.shields.io/pypi/l/jinja2-indent.svg)](https://pypi.org/project/jinja2-indent/)## Compatibility
- `python` >= 3.9
## Installation
Install the latest release with pip:
```shell
pip install jinja2-indent
```## Usage
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.
### Example
The following example demonstrates how to increase the indentation of a block of text:
```jinja2
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:
```jinja2
- 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
```