How to get rid of an extra space in a twig date field template?

by Patrick Kenny   Last Updated November 14, 2017 17:07 PM

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>
Tags : theming 8 datetime

Related Questions

Trying to render a custom date format with Twig

Updated December 28, 2016 08:03 AM

How can I get Node Creation Date?

Updated March 21, 2017 10:07 AM

How to print custom date format in Twig?

Updated November 04, 2017 21:07 PM

Change the "Submitted by" date type?

Updated November 17, 2017 22:07 PM