Jump to content

How do you set the homepage?


Sinmok
 Share

Recommended Posts

Hi all,

I need to switch out which page represents the home page. I have a lot of field data in the existing home page but have been advised that the home page needs to be swapped out for another existing page.

Both pages already have a lot of data so re-doing them would take a lot of time and effort. Is there a way I can switch out the home/root page? I can't seem to move them.

Alternatively, is there a way I can copy the home page? Then I could just call $pages->get("/")->home_page->render() in the home template without losing everything I've done.

Cheers

Link to comment
Share on other sites

How do you clone the home page? There's no copy option. Does it have to be done via the API?

Edit: Just tried cloning the homepage and setting the clone's parent as the homepage through the API and I'm getting an error saying I can't edit the ID of a system page =\

Link to comment
Share on other sites

There's a chance this isn't doable even with the api, as you always need to set a parent to save a new page. 

Edit:

I need to think before I write:

- Create a new page with the same template as the homepage.

- Copy all the data over from the homepage to the clone, easiest via the api.

- Now you can easily override the homepage with the template of the new homepage site.

- Copy the data over from the existing site to the homepage.

- Delete the old site, which should now be the homepage

Link to comment
Share on other sites

It's not that difficult. E.g. for the page which should get the data from the old homepage:

if(...){ //determine if stuff should be imported
  $oldhp = $pages->get("/");
  $new = $page;
  $new->of(false);

  $new->title = $oldhp->title;
  $new->headline = $oldhp->headline;

  $new->save();
}

Maybe even:

foreach($oldhp->fields as $field => $value){
  $new->set($field, $value);
}

The things to remember is, that this will only copy the direct value of the field, so e.g. repeater fields or images must be imported seperatly in the way you normally would fill them via the api, because the hidden pages of the repeater must also be generated and the images have to be uploaded again (which also works via the url to the old file). 

Link to comment
Share on other sites

  • 6 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...