You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{% for term in post.get_terms('post_tag') %}
<span>{{ term.name }}</span>{% if not loop.last %}, {% endif %}
{% endfor %}
Result after beautify
{% for term in post.get_terms('post_tag') %}
<span>{{ term.name }}</span>
{% if not loop.last %},
{% endif %}
{% endfor %}
Problem
The source is rendered as foo, bar, baz while the beautified version is foo , bar , baz.
The new line introduces one whitespace after the <span>.
Honestly I'm not sure what to do here. I see that for HTML you only add a new line, if there is at least one whitespaces after a tag. But applying the same logic to Twig Tags would limit the optimisation options {% if...%}{% if ... }..{% endif %}{% endif %}
Fix
We have to use the "Tag level Line whitespace control" explicitly.
{% for term in post.get_terms('post_tag') %}
<span>{{ term.name }}</span>
{%- if not loop.last -%},
{%- endif -%}
{% endfor %}
Yes, as a beautifier should never change the rendered result. Introducing prettydiff to an existing Twig codebase can result in a change of the rendered output, which is not easy to catch.
No, as I'm not sure, if this problem is solvable or if we just have to adjust the pattern on our side.
We can differentiate between Twig Control structures {% ... %}, Twig Content {{ ... }} and Content in general.
As long as there is at least one whitespace between the last Twig Content / Content and the next Twig Content / Content, introducing a new line is fine.
Only if there is absolutely no whitespace between, we get an issue with adding a line break between.
It's the same situation as we HTML but with the added complexity of the Twig Tags.
Source
Result after beautify
Problem
The source is rendered as
foo, bar, baz
while the beautified version isfoo , bar , baz
.The new line introduces one whitespace after the
<span>
.Honestly I'm not sure what to do here. I see that for HTML you only add a new line, if there is at least one whitespaces after a tag. But applying the same logic to Twig Tags would limit the optimisation options
{% if...%}{% if ... }..{% endif %}{% endif %}
Fix
We have to use the "Tag level Line whitespace control" explicitly.
https://twig.symfony.com/doc/2.x/templates.html#whitespace-control
The text was updated successfully, but these errors were encountered: