diff --git a/docs/templates.rst b/docs/templates.rst index 9f376a13c..1366969e6 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -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: @@ -234,21 +237,14 @@ lines are completely removed: yay -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::
{%+ if something %}yay{% endif %}
-Similarly, you can manually disable the ``trim_blocks`` behavior by -putting a plus sign (``+``) at the end of a block:: - -
- {% if something +%} - yay - {% endif %} -
+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