Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,15 @@ In the default configuration:
* a single trailing newline is stripped if present
* other whitespace (spaces, tabs, newlines etc.) is returned unchanged

If an application configures Jinja to `trim_blocks`, the first newline after a
template tag is removed automatically (like in PHP). The `lstrip_blocks`
If an application configures Jinja to ``trim_blocks``, the first newline after a
template tag is removed automatically (like in PHP). The ``lstrip_blocks``
option can also be set to strip tabs and spaces from the beginning of a
line to the start of a block. (Nothing will be stripped if there are
other characters before the start of the block.)

Whitespace stripping via ``trim_blocks`` and ``lstrip_blocks`` applies to statements
and comments, but not to expressions.

With both ``trim_blocks`` and ``lstrip_blocks`` disabled (the default), block
tags on their own lines will be removed, but a blank line will remain and the
spaces in the content will be preserved. For example, this template:
Expand Down Expand Up @@ -234,21 +237,14 @@ lines are completely removed:
yay
</div>

You can manually disable the `lstrip_blocks` behavior by putting a
You can manually disable the ``lstrip_blocks`` behavior by putting a
plus sign (``+``) at the start of a block::

<div>
{%+ if something %}yay{% endif %}
</div>

Similarly, you can manually disable the ``trim_blocks`` behavior by
putting a plus sign (``+``) at the end of a block::

<div>
{% if something +%}
yay
{% endif %}
</div>
A plus sign at the end of a block is not supported.

You can also strip whitespace in templates by hand. If you add a minus
sign (``-``) to the start or end of a block (e.g. a :ref:`for-loop` tag), a
Expand Down
Loading