tonicastillo Posted September 26, 2017 Share Posted September 26, 2017 Hi I need to change home page of my one page site. Not only the template, but also content. Actually page tree is like this: Actual home New home I would like to move "New home" to root, and delete "Actual home". I thank this would be easy to do, but I don't know how. Two templates allows to have children. Thanks a lot, (and excuse my english) I love PW! Toni Castillo Link to comment Share on other sites More sharing options...
abdus Posted September 26, 2017 Share Posted September 26, 2017 You can kinda "clone" a page into home page like this, but it can't copy image/file fields (as far as I tested). $source = $pages(1015); $home = $pages(1); $source->of(false); $home->of(false); // change template (remember to create new template file and allow access to guest users in Template > Access) // $home->template = $source->template; foreach($source->template->fieldgroup as $f) { if ($home->hasField($f)) $home->$f = $source->$f; } $home->save(); 1 Link to comment Share on other sites More sharing options...
pwired Posted September 26, 2017 Share Posted September 26, 2017 Quote of my one page site Since this is a one page site as you mentioned there cannot be too much content involved and so I wouldn't bother. Create a backup folder alongside your templates folder, download your template files, delete the pages in the tree and setup a new page in the tree with a template file in your backup folder. You can also make use of Processwires ability to export your templates and fields: https://processwire.com/talk/topic/11720-export-fieldstemplatesconfiguration-from-one-site-to-another/?do=findComment&comment=108958 Link to comment Share on other sites More sharing options...
tonicastillo Posted September 27, 2017 Author Share Posted September 27, 2017 Since this is a one page site there is a lot of content on this page . So I think clone it is the best option. I don't understand why is not a easy way to move a page to root. Thanks @abdus and @pwired! Link to comment Share on other sites More sharing options...
ottogal Posted September 27, 2017 Share Posted September 27, 2017 A workaround - though not really pretty - could be: Assign a new template to the page "Actual home" using this template file (say) redirfirstchild.php: <?php namespace Processwire; if($page->numChildren) $session->redirect($page->child()->url); That would redirect a request of the "Actual home" to the "New home" page. Downside of this: The URL would become something like "yoursite.com/actualhome/newhome/" (whatever pagenames you use). To suppress the "actualhome/" part, you perhaps could use URL segments (I don't have any experience with them). Edit: And you'd keep the "Actual home" page in the tree (content removed, of course). Link to comment Share on other sites More sharing options...
abdus Posted September 27, 2017 Share Posted September 27, 2017 3 minutes ago, ottogal said: redirect a request of the "Actual home" to the "New home" page. That would score worse in terms of SEO, though. Having a homepage that immediately redirects is frowned upon. 3 minutes ago, ottogal said: To suppress the "actualhome/" part, you perhaps could use URL segments (I don't have any experience with them). You cannot supress with urlSegments if the page already exists. From @ryan: Quote Should there be a child page that has the same name as a URL segment that the parent page's template is looking for, the pages in the tree always have precedence. Meaning, URL segments only apply if the requested URL did not resolve to an actual page. As a result, you should avoid using URL segments where you think the page names and URL segments could collide. https://processwire.com/docs/tutorials/how-to-use-url-segments/page2 1 Link to comment Share on other sites More sharing options...
ottogal Posted September 27, 2017 Share Posted September 27, 2017 You're right. Bad idea. Link to comment Share on other sites More sharing options...
ottogal Posted September 27, 2017 Share Posted September 27, 2017 9 minutes ago, abdus said: You cannot supress with urlSegments if the page already exists. From @ryan: https://processwire.com/docs/tutorials/how-to-use-url-segments/page2 Good hint. I didn't know it - that is, I don't know nothing about URL segments. (So shouldn't give any advices... sorry!) Link to comment Share on other sites More sharing options...
abdus Posted September 27, 2017 Share Posted September 27, 2017 They're quite useful for handling dynamic urls, I'd really suggest practice using them in a project. You're missing out. Link to comment Share on other sites More sharing options...
tonicastillo Posted September 27, 2017 Author Share Posted September 27, 2017 Thanks @ottogal I used @abdus clone page code and it worked perfect, except images, like he said, but it not a big deal. Thanks! Link to comment Share on other sites More sharing options...
abdus Posted September 27, 2017 Share Posted September 27, 2017 You might be able to get them working by copying from /site/assets/files/<sourcepageid> to files/1 Link to comment Share on other sites More sharing options...
tonicastillo Posted September 27, 2017 Author Share Posted September 27, 2017 Good idea! Link to comment Share on other sites More sharing options...
abdus Posted September 27, 2017 Share Posted September 27, 2017 You should also note that the images inside the html CKE fields will still point to the source page. So copying images alone may not be sufficient. Link to comment Share on other sites More sharing options...
tonicastillo Posted September 27, 2017 Author Share Posted September 27, 2017 This is not the case, but thanks. Link to comment Share on other sites More sharing options...
horst Posted September 27, 2017 Share Posted September 27, 2017 To clone the page seems to be the cleanest approuch after the file/image thing is covered too. But maybe an Alternative could be to alter the home-template file to get the new page and render this in the home url. Link to comment Share on other sites More sharing options...
adrian Posted September 27, 2017 Share Posted September 27, 2017 4 hours ago, abdus said: You should also note that the images inside the html CKE fields will still point to the source page. So copying images alone may not be sufficient. I have no idea why this isn't in the core, but if you are cloning, be sure to use this module: http://modules.processwire.com/modules/process-page-clone-adapt-urls/ 4 Link to comment Share on other sites More sharing options...
Robin S Posted February 15, 2023 Share Posted February 15, 2023 A new addon action module for Admin Actions created to meet this need: 3 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