Skip to content
Myr

document `lstrip_blocks`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kristi Tsukida · committed by Kristi Tsukida · parent ea50f77 · Browse files · 1 file+30 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+30 added−2 removed

  • other:+30 added−2 removed

1 file+30 added−2 removed

modified:docs/templates.rst+30 added-2 removed
154 unmodified lines
155In the default configuration, a single trailing newline is stripped if156present, and whitespace is not further modified by the template engine. Each157whitespace (spaces, tabs, newlines etc.) is returned unchanged. If the158application configures Jinja to `trim_blocks` the first newline after a a159template tag is removed automatically (like in PHP).159template tag is removed automatically (like in PHP). The `lstrip_blocks`160option can also be set to strip tabs and spaces from the beginning of161line to the start of a block. (Nothing will be stripped if there are162other characters before the start of the block.)163164With both `trim_blocks` and `lstrip_blocks` enabled you can put block tags165on their own lines, and the entire block line will be removed when166rendered, preserving the whitespace of the contents. For example,167without the `trim_blocks` and `lstrip_blocks` options, this template::168169 <div>170 {% if True %}171 yay172 {% endif %}173 </div>174175gets rendered with blank lines inside the div::176177 <div>178 179 yay180 181 </div>182183But with both `trim_blocks` and `lstrip_blocks` enabled, the lines with the template blocks are removed while preserving the whitespace of the contents::184 185 <div>186 yay187 </div>188161But you can also strip whitespace in templates by hand. If you put an minus189You can also strip whitespace in templates by hand. If you put an minus190sign (``-``) to the start or end of an block (for example a for tag), a191comment or variable expression you can remove the whitespaces after or before192that block::193
1216 unmodified lines