Hi everyone,
I’m running into a problem with how linters and formatters like djLint handle block tags in Django templates. I often use blocks for simple strings, such as class names, and prefer keeping them on a single line to avoid unnecessary whitespace in the output. For example:
{% block card_column_class %}col-lg-6 mx-auto{% endblock card_column_class %}
When I run djLint, it reformats this into:
{% block card_column_class %}
col-lg-6 mx-auto
{% endblock card_column_class %}
This adds newlines and indentation, introducing extra whitespace in the rendered HTML. Although browsers typically handle extra spaces in class attributes, I’d prefer to keep the output clean and concise.
For blocks with multiple lines of HTML or complex content, the multi-line formatting makes sense, but for simple cases like this, it feels excessive. Right now, I have to disable the linter or formatter for those lines, which isn’t ideal as it disrupts the workflow.
Has anyone else dealt with this? Is there a recommended approach in Django for managing this?
I’d love to hear your thoughts, workarounds, or suggestions. Thanks in advance!