Manually throw 404 from Controller

Hey friends,
is there a way to manually throw a 404 error from a controller, complete with passing everything off to the default 404 handler?
I know I could do $kirby->response()->code('404') to get the header right and then hack something into the template to include the 404 error template instead, but that’s too hacky for my tastes.
Thanks!

Why don’t you send the user to the error page?

go('error');

What’s your use case?

For example, when building a simple blog tag system with an URL like /blog/tag:foobar - if foobar is not a valid tag, the user should see a 404 page under that URL.

This should work:

return function ($page) {
    
    if ('your condition') {
        echo page('error')->render();
        exit();
    } else {
       
        return [
           //...
        ];
    }

};