Jump to content

Recommended Posts

Posted

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

Posted

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 =\

Posted

I'm sorry. I haven't tried the module myself. If it doesn't offer cloning of the homepage it might be the wrong solution for this task.

Posted

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

Posted

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

I think this is what Sinmok is looking for but can't figure out how (me neither unfortunately).

Posted

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). 

  • 6 years later...
Posted

Temporarily comment out the following line in Page.php and you will be able to clone the home page via the API:

throw new WireException("You may not modify '$key' on page '{$this->path}' because it is a system page");

 

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
  • Recently Browsing   0 members

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