A toggle-able maintenance mode?

Hi All, I’m trying to make some kind of maintenance mode toggle in my back end which when activated would force any viewer to see a specific maintenance.php template instead of the standard website. I have a toggle in my site.yml as well as a template and blueprint setup but i cant figure out how to force the redirect. Any help would be appreciated.

sections:
maintenance:
type: fields
fields:
maintenance:
label: Maintenance mode
type: toggle
text:
- Site live
- Maintenance
default: false
help: Show the maintenance page to visitors

Hi, I use this in my own website, on very top of header.php snippet:

if(
!kirby()->user() &&
$site->maintenance()->isTrue() &&
$page->uid() != ‘maintenance’)
{
go(‘maintenance’);
}

Another alternative is this plugin:

Thats for this, after some testing and some help on the discord I managed to get it to work with this
if (
site()->maintenance()->toBool() &&
!kirby()->user() &&
kirby()->request()->path() !== ‘maintenance’
) {
http_response_code(503);
snippet(‘maintenance’);
exit;}
?>

But I am also using SWUP to create smooth transitions and the two seem to clash sadly

This appears to only work with K4, I’m on K5. Will give it a go anyway

my Janitor plugin has a maintenance toggle as well GitHub - bnomei/kirby-janitor: Kirby Plugin for running commands like cleaning the cache from within the Panel, PHP code, CLI or a cronjob