Current situation
Currently, adding a - to a twig tag causes whitespace removal.
E.g. {#- some comment #}, here whitespace is removed before but not after the comment.
Without the -, a single whitespace between twig tags is removed, but a double line break \n\n is not.
Proposal
I would like to propose a new mechanism that turns this around.
We introduce a new mode-switching twig tag {% spaceremoved %}, which would typically be placed at the top of a template.
(I would call it "spaceless" but that term now has a history. Open to suggestions.)
This allows to opt-in to this mechanism per template or per snippet, thus avoiding BC problems.
When this mode is enabled:
- A twig tag without
- is treated as if it had -. E.g. {# some comment #} is treated like {#- some comment #}.
- A twig tag with
+ is treated like a regular tag without -. So, {#+ some comment +#} is treated like {# some comment #}.
Example
{% spaceremoved %}
hel {# remove space before and after #} lo {#+ keep space before #} world
This is equivalent to
hel {#- remove space before and after -#} lo {# keep space before -#} world
which prints as
See also
I found
Current situation
Currently, adding a
-to a twig tag causes whitespace removal.E.g.
{#- some comment #}, here whitespace is removed before but not after the comment.Without the
-, a single whitespace between twig tags is removed, but a double line break\n\nis not.Proposal
I would like to propose a new mechanism that turns this around.
We introduce a new mode-switching twig tag
{% spaceremoved %}, which would typically be placed at the top of a template.(I would call it "spaceless" but that term now has a history. Open to suggestions.)
This allows to opt-in to this mechanism per template or per snippet, thus avoiding BC problems.
When this mode is enabled:
-is treated as if it had-. E.g.{# some comment #}is treated like{#- some comment #}.+is treated like a regular tag without-. So,{#+ some comment +#}is treated like{# some comment #}.Example
{% spaceremoved %} hel {# remove space before and after #} lo {#+ keep space before #} worldThis is equivalent to
which prints as
See also
I found