I apologize if this is off-topic, I’m just wondering if there is a Kirby-specific solution here. If not, any help is appreciated!
So, I have a splash, and a home page. Right now, the splash is just a simple overlay that fades out when you click on it (jQuery), revealing the home page.
What I would like, is if the user visits the root URL, the splash loads, but if the user goes to /home, the splash doesn’t load. It would also be nice if the URL changes to /home when the splash is clicked, but this would probably require some AJAX or something. How would I achieve this?
You can set a unique page up for the splash screen, and make it the home page in the config.
return [
'home' => 'splash'
];
Then your existing home page should be accessible at /home. No need to ajax it i dont think, unless you still want it to load over the home page to reveal it. There are a few javascript page transition libraries out there that will make it feel like it is loading over the page, despite being separate pages.
If you don’t want to create a page and just want to return some content, or if you want to make this more dynamic (e.g. let the user set a splashscreen in the site) you can also do it like this:
'routes' => [
[
'pattern' => '/',
'action' => function () {
$site = site();
$uri = $site->splashscreen();
return new Kirby\Cms\Response(page($uri)->render(), 'text/html');
}
],
[
'pattern' => 'home',
'action' => function () {
return new Kirby\Cms\Response(page('home')->render(), 'text/html');
}
]
],
I think I will go with the simpler solution for now, but this is interesting. Would $site->splashscreen() refer to a page select field on the site blueprint in this case?
Yes, either a pages field or simple select. The code is just basic example, in reality you would have to check for an existing page before calling the render method, of course.
if($page = $site->splashscreen()->toPage()) {
return new Kirby\Cms\Response($page->render(), 'text/html');
}
I plan to serve a static html file (splash page) generated outside Kirby. I want to use the routes (thank you, texnixe):
‘pattern’ => ‘/’,
‘action’ => function () {
$html = F::load(kirby()->root(‘content’) . ‘/splash/splash-1.html’);
return new Kirby\Cms\Response($html, ‘text/html’); }
Got stuck with an error: “Cannot set response code - headers already sent”. I solved the error by killing the function send() in kirby/src/Http/Response.php:
> public function send(): string
> {
> // send the status response code
> // http_response_code($this->code());
>
> // send all custom headers
> // foreach ($this->headers() as $key => $value) {
> // header($key . ': ' . $value);
> // }
>
> // send the content type header
> // header('Content-Type:' . $this->type() . '; charset=' . $this->charset());
>
> // print the response body
> return $this->body();
> }
Kirby serves my splash screen now However, I cannot access the panel Apparently these lines have a meaning!
I am working on Kirby 4.3. Is the there any update to the routes?
Anyone can help?