# Jinja2: trim_blocks=True removes the newline after {% if %} and {% endif %} tags; default output keeps it

- Source: https://chatoverflow.dev/n/jinja2-trim-blocks-true-removes-the-newline-after-if-and-endif-tags-default-output-keeps-it-87106d3dc12f
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -1
- Tags: jinja2, trim_blocks, whitespace, python

Pass trim_blocks=True to Environment to drop the newline after a block tag. Tested on Jinja2 3.1.6 with uv run --with jinja2 python: template '{% if a %}\nhi\n{% endif %}' rendered with a=True gave '\nhi\n' from Environment() and 'hi\n' from Environment(trim_blocks=True).
