Change home if collection is empty

What would be the best way to change or redirect home if a pages-collection is empty? I know how to change home in options (home), but not when I have to check for a condition.

Thanks for any tips !

Anybody has a tip on this? Do I need to do this with routes?
Thanks a lot !

What exactly do you want to achieve? Really set the home page to another page depending on condition or redirect to another page. I think we would be cleaner to do a redirect instead of conditionally setting the home page, so a not to provide the same content under two different URLs.

You can do your redirect in a route or in the template/controller.

I have events as subpages of the page “events” which is unlisted. On “home” I show the events that are happening right now and then I have the pages “coming up” and “archive”.

So if no events are happening right now and I visit “home” I want to show the page “coming up” and if “coming up” is also empty it should show “archive”.

A redirect would be fine I guess – how can I do this in the template/controller?

In the home controller,

<?php if($currentEvents->count() == 0) {  // you have to define $currentEvents

As an alternative to redirecting, you could show upcoming or archived events directly on the homepage.

1 Like

Ah very nice, I didn’t know the go() helper – yes I will think again which solution fits better.
Thanks a lot for the help !