Permalink
Browse files

document `lstrip_blocks`

  • Loading branch information...
1 parent ea50f77 commit 214bb361c0642f3d7efb5f415c5aab837828251b @kristi committed Jul 11, 2012
Showing with 30 additions and 2 deletions.
  1. +30 −2 docs/templates.rst
View
32 docs/templates.rst
@@ -156,9 +156,37 @@ In the default configuration, a single trailing newline is stripped if
present, and whitespace is not further modified by the template engine. Each
whitespace (spaces, tabs, newlines etc.) is returned unchanged. If the
application configures Jinja to `trim_blocks` the first newline after a a
-template tag is removed automatically (like in PHP).
+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
+line to the start of a block. (Nothing will be stripped if there are
+other characters before the start of the block.)
+
+With both `trim_blocks` and `lstrip_blocks` enabled you can put block tags
+on their own lines, and the entire block line will be removed when
+rendered, preserving the whitespace of the contents. For example,
+without the `trim_blocks` and `lstrip_blocks` options, this template::
+
+ <div>
+ {% if True %}
+ yay
+ {% endif %}
+ </div>
+
+gets rendered with blank lines inside the div::
+
+ <div>
+
+ yay
+
+ </div>
+
+But with both `trim_blocks` and `lstrip_blocks` enabled, the lines with the template blocks are removed while preserving the whitespace of the contents::
+
+ <div>
+ yay
+ </div>
-But you can also strip whitespace in templates by hand. If you put an minus
+You can also strip whitespace in templates by hand. If you put an minus
sign (``-``) to the start or end of an block (for example a for tag), a
comment or variable expression you can remove the whitespaces after or before
that block::

0 comments on commit 214bb36

Please sign in to comment.