Is there a tidy-like tool or a tidy configuration, which works fine with Jinja2 templates? The default tidy has problems with Jinja code in attributes and Jinja-loops are formated in an unreadable way. My main requirement is to get the indentation level right. Everything else is nice to have, but not required.
To reuse a Jinja template you use the Jinja built-in {% extends %} tag. The {% extends %} tag uses the syntax {% extends <name> %} to reuse the layout of another template. This means that in order to reuse the layout in listing 4-5 defined in a file base.
Jinja is a fast, expressive, extensible templating engine. Special placeholders in the template allow writing code similar to Python syntax. Then the template is passed data to render the final document.
A standalone (Jinja2 lint like) tool can be found here:
https://github.com/ramonsaraiva/jinjaninja
Install:
$ pip install jinjaninja
Usage:
$ jinja-ninja templates/header.html
Output example:
templates/header.html:8:68 Block closures should also have names `{% endblock %}`
Check jinjaninja@github for more information
If as part of your local git setup you use pre-commit, check the
If you use Django Templates, I suggest to use django-extensions and make use of: validate_templates
You can use pip to install django-extensions for usage:
$ pip install django-extensions
Django project settings.py file.:
INSTALLED_APPS = [ ...
'django_extensions',
]
The next time you invoke ./manage.py help you should be able to see all the newly available commands. One is called "validate_templates"
$ python manage.py validate_templates
Visual Code offers two Jinja extensions, the default is "Jinja" but a newer one with more functionality is:
While it is not a standalone tool like HTML Tidy, the atom-beautify package for the Atom text editor works fine for me. I use atom-beautify when developing Flask/Jinja2 applications.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With