Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

3.1.12 set_create_default_pages / normal setup vs. custom StartPage


Go to End


6 Posts   1183 Views

Avatar
timo

Community Member, 47 Posts

14 May 2015 at 8:56pm

Edited: 14/05/2015 9:09pm

Some projects need a custom Startpage extended from SiteTree, other dont.
Until now ive hacked into cmc/code/model/SiteTree.php and changed line ~ 1464 to $homepage = new SartPage();
Thats not very comfortable. To make things more flexible i am trying to set :

_config.php:

// SiteTree create StartPage? // true = normal setup // false = creates custom StartPage
SiteTree::set_create_default_pages(false);

and on Startpage.php:
class StartPage extends SiteTree  {
	
	
	public function requireDefaultRecords() {
		parent::requireDefaultRecords();
		
		if(!$this->config()->create_default_pages) {	
			if(!StartPage::get()->exists()) {
				$page               = new StartPage();
				$page->Title        = 'StartPage';
				$page->URLSegment = Config::inst()->get('RootURLController', 'default_homepage_link');
				$page->Sort = 1;
				$page->Content      = 'the StartPage page test';
				$page->Status       = "Published";
				$page->write();
				$page->publish('Stage', 'Live');
				DB::alteration_message('StartPage created', 'created');
			}
		}
	}

public static $allowed_children = 'none';
	
	function canCreate($Member = null){
			return false;
	}
	
	function canDelete($Member = null){
		return false;
	}
	
	function canDeleteFromLive($Member = null){
		return false;
	}
	
	public static $hide_ancestor = 'StartPage';

Now the StartPage is created but ErrorPages are missing.
(Forget about -> About Us and Contact Us ) as ?nobody? needs them.
In cmc/code/model/ErrorPage its the same if clause:

if ($this->class == 'ErrorPage' && SiteTree::config()->create_default_pages) {

How can i manage to create the custom StartPage and the default ErrorPages ?

Thanks.timo.

Avatar
wmk

Community Member, 87 Posts

14 May 2015 at 9:15pm

Hi timo,

maybe the populate module might help you with this setup task. Just disable standard creation of default pages and define the pages you want created in a yml.

It's also good for creating another bunch of default pages and dataobjects.

cheers, wmk

Avatar
timo

Community Member, 47 Posts

14 May 2015 at 9:31pm

Hi wmk!
Thanks for your hint. But looking at this module makes me think that its a bit overloaded for just creating a StartPage or not.
Maybe i come back to this when things get more complex.
Meanwhile i am still looking for a more simlpe solution.
I have to think this over.
timo.

Avatar
Pyromanik

Community Member, 419 Posts

15 May 2015 at 12:04am

Edited: 15/05/2015 12:08am

requiredefaultrecords is for putting in some default records (perhaps necessary ones like SiteConfig) - it is not generally for defining site structure, etc.

SiteTree has this as example content, and is only effectively used on the very first build - the installation build.

There is a bit of an issue that if your homepage isn't URLSegment 'home' it will be renamed - be careful of that. I think as wmk says you can disable the requiredefaultrecords call.

Instead of hacking SiteTree.php, you should edit your StartPage.php requiredefaultrecords to get the homepage, and set it if it either doesn't exist, or isn't of type StartPage (ie, change it's type).
As it seems you're aware, never touch the core code :< Very 'uncomfortable' indeed.

Avatar
timo

Community Member, 47 Posts

15 May 2015 at 1:48am

Edited: 15/05/2015 1:49am

@Pyromanik : )

do you have a solution?
timo.
(image: Saul Steinberg)

Avatar
Pyromanik

Community Member, 419 Posts

19 May 2015 at 8:47pm

Just as I described in the my last paragraph.
If you're asking for code I think you'd learn more by doing it. Use the SiteTree function as a base and go from there.