I have a twig date field template that has a mysterious extra blank space that I want to remove.
In my twig template, field--comerce-product--field-ppromotion-enddate.html.twig
, I have the following line:
<div{{ item.attributes.addClass('field--item') }}><span class="green">{{ item.content }}{{ 'TEXT'|trans }}</span></div>
Unfortunately, the printed output looks like this:
2017-12-25 TEXT
I don't know where the space is coming from.
I am using a similar template for an integer field that has this line:
<div{{ item.attributes.addClass('field--item') }}><span class="discount">{{ item.content }}{{ 'OFF!'|trans }}</span></div>
This prints the discount percentage (integer field) and then the word "off" (example: 20%off
)-- there is no space between the percentage and off, which is what I want.
(Why no space? My site actually uses an Asian language that doesn't use spaces.)
So where is this space coming from on the date field? When the date field content is printed, it uses the template time.html.twig
, but the content of that template is this single line (skipping the comments):
<time{{ attributes }}>{{ text }}</time>
EDIT: Based on the suggested answers, I have tried {{- foo -}}
to remove the whitespace around the date and text, as well as {%spaceless%}
to remove other whitespace, but the extra space is still there between the date and the text):
{% spaceless %}
<div{{ item.attributes.addClass('field--item') }}><span class="green">{{- item.content -}}{{- 'TEXT'|trans -}}</span></div>
{% endspaceless %}
Actual output of this code: 2017年12月25日 TEXT
Output should be: 2017年12月25日TEXT
{{- foo -}}
but that didn't seem to have any effect (cleared the cache, etc.)