Address output missing spaces (e.g. first / last name)

Created on 18 November 2024, 4 months ago

Problem/Motivation

Address field from the widely used Address module uses this twig template: https://git.drupalcode.org/project/address/-/blob/2.1.x/templates/addres...

Outputting the address data, spaces are missing between subfields of the address output, e.g. first name and last name are missing a space.

Expected:
John Doe

Actual:
JohnDoe

Steps to reproduce

  1. Install and enable radix
  2. Install and enable address module
  3. Place an address field in an entity type
  4. Create a field value for the address field filling all fields
  5. See the missing spaces
  6. Switch to Claro and see the address shown correctly

Proposed resolution

Probably this is caused by an {% apply spaceless %} too much in a (field) template?

Remaining tasks

  1. Find the root cause
  2. Fix the root cause
  3. Test
  4. Release

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

6.0

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica
  • I can confirm this is because {% apply spaceless %} wraps basically each SDC.

    Personaly I use spaceless not very often, because of such problems. I just fix very specific bugs with it.

    So from my point of view it should be removed from most (if not all) of the SDCs?

    Maybe {{- -}} / {{~ ~}} are better options if trimming is required, guess those have less impact: https://twig.symfony.com/doc/2.x/templates.html#whitespace-control

  • I agree, we should get rid of {% apply spaceless %}
    I would really appreciate a MR if possible

  • Pipeline finished with Failed
    3 months ago
    Total: 130s
    #350925
  • 🇮🇳India Tirupati_Singh

    Hi all! I've also replicated the issue following the steps to reproduce and found that the problem was caused by the use of the spaceless filter in the Twig templates. I have removed the filter from the affected templates, please review the MR changes. I'm attaching the screenshots of the before and after fixes for reference.

    @doxigo, I have only removed the filter from the templates associated with the address module. Would you recommend removing the filter from all template files, or should we limit the changes to these specific ones?

    Thanks!

  • Hello,
    I followed the steps to reproduce the issue by installing the theme version ( 6.0.0-rc6 ) in Drupal version ( 10.4.0 ) along with the address module. Using the address field entity type created a field and added content to the field. On viewing the page I encountered the missing space between the content like name, city and pincode hence I cross checked the spacing in two themes namely Claro and Olivero. I applied the MR!113 which applied cleanly. On revisiting the node page I found the space has been included similar to the other themes. I reviewed the MR!113, the apply spaceless filter has been removed from the required templates as mentioned by @tirupati_singh. The mentioned issue has been resolved therefore moving to RTBC. Attached ss of before and after for reference.
    Thanks

  • 🇺🇸United States danchadwick Boston

    Personally, I'd prefer to see spaceless retained and the affected templates modified (or fixed). The intention is to feel free to format templates liberally as if they are source code (which they are), and yet in production not generate a ton of wasted whitespace.

  • 🇺🇸United States danchadwick Boston

    Here's a patch intended to be applied to commit #15244b15 which simply removes all the spaceless tags and adjoining whitespace. Because it touches 56 files, it will would be ideal to commit this before other patches.

    It was created by making the following regex deletions using my IDE:
    \{% apply spaceless %\}\n\s*
    That matches {% apply spaceless %}, followed by a new line and additional whitespace.

    ^\n*\s*\{% endapply %\}\n*
    That matches the start of a line, optional whitespace, followed by {% endapply %} and optional additional newlines.

    I have looked at the file changes in all 56 files and confirmed that the regex replacements worked as intended.

    The spaceless filter causes my site a number of display and semantic errors.

    • danchadwick committed 2f4a7632 on 6.0.x
      Issue #3488216 by anybody, thomas.frobieter, tirupati_singh, esha_kundu...
  • 🇺🇸United States danchadwick Boston

    Committed to 6.x. This resolves the issue of semantic and display errors when two HTML tags abut with intended whitespace between them. A good example is an inline field with span tags around the label and the field contents.

    If you would like to remove some of the extraneious whitespace from the HTML output, I would welcome a new issue and MR/patch for using fine-grained Twig whitespace control using the dash and tilde modifiers to opening/closing tag syntax.

  • Status changed to Fixed about 1 month ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024