Sinmok Posted July 9, 2014 Share Posted July 9, 2014 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 More sharing options...
totoff Posted July 9, 2014 Share Posted July 9, 2014 (edited) Hi Sinmok, a quick search brought me to this module: http://modules.processwire.com/modules/process-page-clone/ Not sure if it does what you want but maybe it's worth to check. Also this discussion might help: https://processwire.com/talk/topic/1683-move-or-copy-content-between-pages/ Edited July 9, 2014 by totoff Link to comment Share on other sites More sharing options...
Sinmok Posted July 9, 2014 Author Share Posted July 9, 2014 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 More sharing options...
totoff Posted July 9, 2014 Share Posted July 9, 2014 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. Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 9, 2014 Share Posted July 9, 2014 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 More sharing options...
totoff Posted July 9, 2014 Share Posted July 9, 2014 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). Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 9, 2014 Share Posted July 9, 2014 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 More sharing options...
thetuningspoon Posted August 10, 2020 Share Posted August 10, 2020 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"); Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now