Temporary homepage & Config return array

Hello,

I just finished a website for a client and he asked me if we could have a simple temporary homepage while he uploads the contents on the final website. I created a template for this simple page but I am just not sure on how should I use this template as the homepage and keep the original homepage in the layout so he can upload the contents and see how it looks, could someone point me in a solution for this? I searched in the forum and saw some options with “c::set(‘home’…” but somehow didn’t understand how to do this and didn’t finde anything on the docs

I also have another question regarding multiple return arrays on the config.php. I was looking on the docs and I should only have 1 array had but when I try to put everything together I get an error, can someone point me in right approach here?

here’s my code:

<?php

return [
    'debug' => true,
];

return [
    'panel' =>[
      'install' => true
    ]
  ];



return [
  'thumbs' => [
    'srcsets' => [
      'default' => [
      '400w' => ['width' => 400, 'quality' => 80],
      '800w' => ['width' => 800, 'quality' => 80],
      '1024w' => ['width' => 1024, 'quality' => 80],
      '1440w' => ['width' => 1440, 'quality' => 80],
      '2048w' => ['width' => 2048, 'quality' => 80],
      ]
  ]
  ]
];

thank you so much and sorry for so many questions but I’m quite new to php & kirby.

  1. You can set another page as home page in your config:
<?php

return [
    'debug' => true,
    'home' => 'some-other-page'
];

If you do it like this, you should make sure that all other templates go to the error page (either add a redirect in your templates or use a route) or are in draft status.

  1. You can only use one return statement. Why? It’s important to understand what return does: it returns the control to the calling script, which means that anything that comes after a return statement is ignored. Of course, a script/function can have multiple return statements when it uses conditions, e.g. stupid example:
<?php

if ($a === $b) {
  return true;
}
return false;

So your config should look like this:

<?php

return [
    'debug' => true,
    'home' => 'some-other-page',
    'panel' => [
        'install' => true // should be remove once installed on remote server
    ],
    'thumbs' => [
        'srcsets' => [
            'default' => [
                '400w' => ['width' => 400, 'quality' => 80],
                '800w' => ['width' => 800, 'quality' => 80],
                '1024w' => ['width' => 1024, 'quality' => 80],
                '1440w' => ['width' => 1440, 'quality' => 80],
                '2048w' => ['width' => 2048, 'quality' => 80],
            ]
        ]
    ]
];

If you got an error, maybe there was a comma or closing bracket missing.

thank you so much for the answer and explaining the importance of return, just one to make sure that I understand the debug as well, the debug should be false as soon as the website goes online right? thank you once again!!

Yes!

On a side note, you can use multiple config files per domain, e.g. on the one for localhost you can set debug to true, on production to false (so you don’t have to remember to change your settings):

Hi @texnixe sorry for another question but I just set up the original home, about & projects to drafts but then they are not accessible via the panel and therefore the client cannot update them. is there a way to keep them visible in the panel? on the content folder they are “01_projects” “02_about” & home folders. I need to access them via the panel while the temporary homepage is published so the client can update them.

Whether they appear in the Panel or not doesn’t depend on their status, rather how your sections are set up.

If your pages have a prepended number they are not drafts, anyway.

However, it might make more sense if you follow my first suggestion and redirect all templates apart from the temporary one and the imprint to the error page if user is not logged in.

I have a drafts section my site.yml and I see it on my panel but if I change 03_about to drafts it just disappears completely on the panel, I can see iit on my content folder under drafts and without the number but on the panel is just gone. do you know why this happens?

To redirect all templates can I use something like this: <?php
if(!$site->user()->isTrue()) go(‘error’) ?>

it seems to be working but added as a snippet and now I need to add it to all templates, is there a way to do this in a more simple way so I don’t have to go to each template again when the pages are ready? thank you so much!

Nope, because $site->user() method doesn’t exist. Should be

<?php if (! $kirby->user()) {
  go('error');
}
?>

Not without your site.yml blueprint

thank you I just updated the redirect and it’s working, and is this a good way to add this code to a snippet and add this snippet to each template or is there a better way?

I just realised why the drafts were not working, I had a template on the blueprint that’s why. Do you think it’s still better to use the redirect? I am just wondering because then when the pages are ready to go online I need to remove the redirect

The alternative is a route

thank you, I will look into that!

Routing guide: Routing | Kirby CMS

You can use a single route with an array of ids as pattern like this:

    'routes' => [
        [
            'pattern' => ['home', 'about', 'projects', 'projects/(:any)'],
            'action'  => function () {
                if (! kirby()->user()) {
                    go('error');
                }
            }
        ]
    ],

This would go into your config’s return array.

Thank you so much, I just tried the route way and deleted the snippet but now I always go to the error page even if I’m logged in. not sure why this is happening

Ok, then we have to do something when the condition is not true:

    'routes' => [
        [
            'pattern' => ['home', 'notes', 'notes/(:any)', 'photography', 'photography/(:any)'],
            'action'  => function () {
                if (! kirby()->user()) {
                    go('error');
                }
                $this->next();
            }
        ]
    ],

thank you, this works!!