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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Customising the CMS /

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

Auto Add new pages

Go to End

3 Posts   1068 Views


Community Member, 11 Posts

6 October 2010 at 8:46am

Hello -
I am not sure if I can do this, so I thought I'd ask here.
I want the CMS to be able to add a Page automatically when other pages are added and certain conditions are met.

For example:
I have pages that include data for a city and state. I have city and state pages that act as directories for these products. Is there a way that I can add a page, have the CMS check if that city and state already exists, and if it doesn't, then add pages for the city and state? That way, a default one can be made, but a user can go and edit content for that city later if they want.

Thanks in advance!


Forum Moderator, 1899 Posts

6 October 2010 at 9:21pm


I'd recommend overriding onAfterWrite function Page that you are adding, then that can call a function like the following to create the page if "certain conditions are met"... and make sure that the page has not already been created is one of those conditions

	function makePage($pg,$URLSegment,$Title,$strContent,$bShowInMenus,$bShowInSearch,$iParentID=-1)
		$pg->URLSegment = $URLSegment;
		$pg->Title = $Title;
		$pg->MenuTitle = '';
		$pg->Content = $strContent;
		$pg->MetaTitle = '';
		$pg->MetaDescription = '';
		$pg->MetaKeywords = '';
		$pg->ExtraMeta = '';
		$pg->ShowInMenus = $bShowInMenus;
		$pg->ShowInSearch = $bShowInSearch;
		$pg->HomepageForDomain = '';
		$pg->ProvideComments = '';
		$pg->Sort = '';
		$pg->HasBrokenFile = false;
		$pg->HasBrokenLink = false;
		$pg->Status = '';
		$pg->ReportClass = '';
		$pg->CanViewType = 'Anyone';
		$pg->CanEditType = 'LoggedInUsers';
		$pg->ToDo = '';

		if ($iParentID!=-1)
			$pg->ParentID = $iParentID;


		$pg->publish("Stage", "Live");

		return $pg->ID;


	new Page(),


Community Member, 11 Posts

15 October 2010 at 6:39pm

Perfect. Thanks! I haven't added all the code yet, but this is definitely enough to get me going.