tonicastillo

Newbie question: How change homepage

Recommended Posts

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

Share this post


Link to post
Share on other sites

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();

 

  • Like 1

Share this post


Link to post
Share on other sites
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

 

Share this post


Link to post
Share on other sites

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!

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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

  • Like 1

Share this post


Link to post
Share on other sites

They're quite useful for handling dynamic urls, I'd really suggest practice using them in a project. You're missing out.

Share this post


Link to post
Share on other sites

You might be able to get them working by copying from /site/assets/files/<sourcepageid> to files/1

Share this post


Link to post
Share on other sites

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. 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

 

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/

  • Like 4

Share this post


Link to post
Share on other sites

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.

  • Similar Content

    • By JurgenP
      First of all I'm as new to ProcessWire (PW) as they come, so bear with me if I ask stupid questions with obvious answers.
      I started looking into PW because I'm looking for something that would take out some of the grunt work of building an applications, yet be flexible enough to be able to implement custom functionality.
      I'm trying to work out if PW is suitable for my needs, ...
      A the moment I'm trying to create an architecture for a web platform on which multiple websites/webshops (750-1000) for pharmacists will be run.
      The websites will have different types of information, obviously there will be the 'own' pages the pharmacists create themselves.
      But as pharmacists tend 'not to be computer people' there is also content provided by the platform to make the site look alive, as well as public health information provided by the goverment.
      I was wondering if there is a way to structure/set up PW so that they have full access to their own content, and limited access (basically chose to publish it or not) to the externally provided content.
      Also is there a way to have the templates/page for the own content located in their own folder, and the 'external ones' in a shared folder so that they don't have to be repeated 1000 times on the server (and if modifications need to be done, it only has to be done once as well).
      Sincerely,
      Jurgen
    • By nickngqs
      Does anyone know how to do an export of a page entries to CSV using the Processwire way?
      I'm trying to setup a list where the client can see a list of user's form values.

      Example ->
      A front end form -> Upon submit -> Adds to database -> Shows on the admin of Processwire.

      From there, I can see the entries and sort stuff. And lastly I can export them in CSV.

      I'm looking at the Processwire cheatsheet and see the $files, is this the one I should be looking at? 
    • By cosmicsafari
      Hi all,
      Im a bit confused by an issue I have come across today.
      I have a module which connects to a third party (once an hour using LazyCron), parses a publicly available XML file, turns it into useable information which I then use the API to save as PW Pages.
      On the whole this has been working great however today I noticed that it kept failing on one of the imports.
      After doing some investigation I realised its appears to be dying at the save page stage.
      From the documentation $page-save() should return either True/False, so I thought I would update the code to reflect this while debugging.
      $this->log(1); $bool = $p->save(); if($bool){ $this->log('Saved successfully'); } else { $this->log('Fail to save'); } $this->log(2); However the script only gets to the save() part and then appears to terminate. Then when checking the error log the latest entry is always just '1'
      Any ideas as i'm a tad confused why I at least don't get a response of some kind?
       
       
       
    • By Mirza
      Hi All,
      Arabic content changes not available in page getChanges method
      While editing the page from admin panel in the multi-language field, added a hook to save the changes made to the page.
       
      $this->pages->addHookAfter('saveReady', $this, 'hookUpdateLog');  
      public function hookUpdateLog(HookEvent $event) { $page = $event->arguments[0]; if(in_array($page->template->name, $this->templateList)) { $this->logFieldChanges($page); } } public function logFieldChanges($page) { $changes = $page->getChanges(); //This changes does not contain the field of arabic changes. }
      Please let me know, If I am approaching in a right way.

    • By ov3rtak3r
      Hello everyone!
      I am new to Processwire and really like it, but now I have a problem that I can't solve by myself.
      I have created following templates:
      data_people (no template-file)
      person_listing (person_listing.php)
      person_detail (person_detail.php)

      I have added the following Pages:
      Actor, Director, Stuff using template person_listing.php [visible in frontend]
      "People" using template data_people [not visible, only for data]
      -> "Georg Klonee" using template person_detail [is visible, but should not be shown using path /en/person/georg-klonee]

      Example Person: Georg Klonee
      The Problem:
      He is a Actor and a Director, so I want him to be shown in the Listing of /en/actors and /en/directors. No problem until here - it works. But now, when I click him, the URL for the Detail-Page is unfortunately /en/person/georg-klonee. But I want it to be /en/actors/georg-klonee, if i open the details from Actors-Page (and of course /en/directors/georg-klonee when on Directors-Page).
      How can I get this to work? I am also using TemplateEngine-Module with TemplateTwigEngine-Module, hopefully this won't be a problem? I tried it with URL-Segments for person_listing.php. But how can I abort the rendering of people_listing and start rendering person_detail.php?
       
      Thanks for your help in advance.