Saving php template file removes closing php tag

Hi there, this is my first post here and I hope I do everything right. I just could not find a solution for this hopefully basic problem and hope someone here can give me a clue:

Somehow when I try to safe any php template in the templates folder it removes the last bracket [?>]

Context: I am new to php. I am working with kirby 4, the project started with the plainkit and is a bit more complex by now.

Screenshot 2024-04-29 at 21.00.52
Screenshot 2024-04-29 at 21.00.48


I only discovered this when I was trying to solve this error, not sure if the issues are related:

Any hint is appreciated

A PHP-only file should not have a closing tag. You only want closing tags when you mix PHP and HTML in your templates.

I.e. controller file (or a PHP class file or whatever)

<?php
return function($kirby, $pages, $page) {

  // code here
};
// no closing tag here

Your IDE probably removes those closing tags automatically.

Template with PHP and HTML:


<h1><?= $page->title() ?></h1>
<?php if ($page->hasImages()): ?>
    <div></div>
<?php endif ?>
1 Like

ohh amazing i did not know that yet, thank you!
I figured then there was still a semicolon missing on my default redirect (<?php go(β€˜error’); ) to stop throwing errors.
The err_too_many_redirects has been solved through that too :heart_eyes: