mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-21 07:37:43 +00:00
Merge remote branch 'markstory/whitespace'
* markstory/whitespace: Updating documentation for whitespace trim tags. Making trim tags consume all whitespace, both horizontal and vertical. Adding additional test suggested by nikic. Making a capturing group non capturing, as the group isn't used. Moving newline trimming into the regexp used to match end of tags. Applying changes suggested by nikic to simplify how end of comments are processed. Fixing some whitespace. Fixing typo. Adding a bit of documentation for whitespace trimming. Adding whitespace trimming support to other tag types (comments, variables) Refactoring how whitespace trimming is done, and moving it into a separate option that is combined with other tag types. Adding more tests. Refs #284 Fixing use of non-existent method name. Adding a test case for mixing {%- and %} tags together. Adding a test that uses tabs. Added a test for trailing tabs and -%} Refs #284 Implementing {%- which trims non-newline whitespace preceding it. Refs
This commit is contained in:
@@ -162,6 +162,36 @@ Use the ``spaceless`` tag to remove whitespace between HTML tags:
|
||||
|
||||
{# output will be <div><strong>foo</strong></div> #}
|
||||
|
||||
In addition to the spaceless tag you can also control whitespace on a per tag
|
||||
level. By using the whitespace control modifier on your tags you can trim
|
||||
leading and or trailing whitespace from any tag type:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% set value = 'no spaces' %}
|
||||
{#- No leading/trailing whitespace -#}
|
||||
{%- if true -%}
|
||||
{{- value -}}
|
||||
{%- endif -%}
|
||||
|
||||
{# output 'spaces' #}
|
||||
|
||||
The above sample shows the default whitespace control modifier, and how you can
|
||||
use it to remove whitespace around tags. Trimming space will consume all whitespace
|
||||
for that side of the tag. It is possible to use whitespace trimming on one side
|
||||
of a tag:
|
||||
|
||||
.. code-block:: jinja
|
||||
|
||||
{% set value = 'no spaces' %}
|
||||
<li> {{- value }} </li>
|
||||
|
||||
{# outputs '<li>value </li>' #}
|
||||
|
||||
..versionadded:: 1.1
|
||||
|
||||
Tag level whitespace control was added in 1.1
|
||||
|
||||
Escaping
|
||||
--------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user