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.

Customising the CMS /

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

Allow for only 1 "HomePage"


Go to End


3 Posts   843 Views

Avatar
Faloude

Community Member, 55 Posts

3 February 2016 at 3:15am

Hi there, I've run into an issue and I just can't seem to find an answer anywhere.

I have a custom pagetype named "HomePage" which extends the standard pagetype "Page". I want to limit the amount of homepages to a maximum of 1. No user should be able to create more than 1 single "HomePage".

How do I pull this off?

Avatar
Devlin

Community Member, 344 Posts

3 February 2016 at 5:13am

class HomePage extends Page {
	public function canCreate($member = null) {
		return !HomePage::get()->exists();
	}
}

Avatar
Faloude

Community Member, 55 Posts

3 February 2016 at 5:32am

And Devlin saves the day once again.