1

There is white space being added to the start of my templates.

This isn't really an issue but because its happening to an RSS template that is breaking the feed and causing it to not validate.

When I edit the template in my text editor the white space is not there, so I think it is Craft adding when when rendering the template?

My code looks like this, you can see on line 1 there are no spaces before I declare the XML version. <?xml

RSS template start

However, on the front end it is rendering like so: I have highlighted the space in blue.

White space being added to RSS doc

Because of this, the RSS template is not validating and is causing my feed to break.

This started recently, I am not sure if it is linked to a recent Craft update but it started happening around the same time.

Craft v3.0.26.1

Any help appreciated :) Thanks

3
  • If I simply drop a test.html file in the public root its not the case. It only occurs when the template is in the templates directory
    – Mark
    Commented Oct 15, 2018 at 8:54
  • 1
    It's not just your main template that could be injecting extra whitespace... it could be coming from included templates. Also, check your public index.php file, your files in craft/config/* and other other files you might have editing that would be included in that RSS feed request.
    – Brad Bell
    Commented Oct 15, 2018 at 17:44
  • @BradBell Thanks for the heads up, there was a couple of spaces at the start of my craft/config/imager.php file.
    – Mark
    Commented Oct 16, 2018 at 7:43

1 Answer 1

2

As Brad kindly pointed out, I checked my files in the config directory and noticed a few spaces before I started the <?php in my /craft/config/imager.php file. I would never have thought to check this, so thanks Brad!

1
  • 1
    Lifesaver! I had the same issue and the volumes.php file had a couple of white spaces in the beginning too. Commented May 15, 2020 at 1:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.