- Issue created by @Anybody
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- Merge request !113Issue #3488216: Fixed the spaces issue for address, removed spaceless filter. → (Closed) created by Tirupati_Singh
- 🇮🇳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...
-
danchadwick →
committed 2f4a7632 on 6.0.x
- 🇺🇸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 1:19pm 23 January 2025 Automatically closed - issue fixed for 2 weeks with no activity.