This a pretty weird issue.
Don’t have a clue about the causes, but now every page of my kirby site now renders three blank lines at the beginning, causing the
<!DOCTYPE html> declaration begins at row no. 4.
It’s not a problem of a single template page, because I’ve checked that it occurs even with a blank template. This is the template:
and this is the page source:
The big issue comes when I try to display the xml feed. Having the xml declaration starting at row no. 4, I get the error message :
error on line 4 at column 6: XML declaration allowed only at the start of the document
Have you got any controllers? or anything that gets included globally? any third party composer type stuff? Ive seen this happen with other PHP cms system, but not with kirby. I think its not blank lines as such, its more white space created by something doing its job. Id look at your plugins and controllers. Sounds like it didnt always do this… have a think what youve changed or plugins uve added lately. Either remove them or update them and see if the problem goes away.
If you cant find the root cause, theres a couple of HTML minifier plugins out there that should strip the blank space. That might make your XML happy again, but I would do that as an absolute last resort. Finding the culprit is a better idea.
My money is on a plugin that needs to do its thing at a high level, before or during the template being put together and rendered.
It was a kirbytext extension I wrote which was adding those damned blank lines… fixed.
Thank you, I spent the past three hours trying to get a clue about this issue…
No worries dude. Glad you sorted it. PHP is a bit funny in that it can generate white space just by working through stuff.
Did you use an end tag at the end of the file, followed by blank lines? It is recommended not to use the closing tag in PHP only files to avoid such issues.
A good editor usually removes blank lines when you save.
Thanks, now I know. I’m using Visual Studio Code.