Twig whitespace controls have no effect on fields I am trying to iterate over a Paragraph field and apply a comma after each Paragraph item.

In the field template that outputs the Paragraph, I am trying:

{%- for item in items %}
  {{ item.content }}{{ not loop.last ? ', ' }}
{% endfor -%}


This puts the comma out, but there is a ton of whitespace all over:



I have tried many whitespace control combinations and none seem to have any effect.

How can I remove this sort of behavior entirely? The paragraph field is an entity reference, that renders a view mode, so I don't want to install field delimeter plugin.

edit: Tried the solutions mentioned here:

How remove whitespace on field in twig?

and here:

https://craftcms.stackexchange.com/questions/2789/whitespace-created-when-using-if-statements

as well as in the documentation.

The structure is as follows:

Node -> Paragraph field -> Paragraph (Entity) -> User Reference + Plain text field + rich text

In this context, only the user field is being rendered, and I want to put a comma at the end of each linked name.
Although the whitespace control modifier is supposed to work for all {{ … }} prints, {% … %} statements and {# … #} comments I'd expect to make your sample work it needs to be put directly into the print like that:

{% for item in items %}
  {{- item.content -}}{{- not loop.last ? ', ' -}}
{% endfor %}


Alternatively you could try to use the {% spaceless %} tag. But again, I'd expect this only works right when placed inside the loop:

{% for item in items %}
  {% spaceless %}
    {{ item.content }}{{ not loop.last ? ', ' }}
  {% endspaceless %}
{% endfor %}



  As of Twig 1.38, use the |spaceless filter instead.