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.

Customising the CMS

Generate Webpages


Reply

4 Posts   370 Views

Avatar
mantasia12

19 September 2013 at 9:58pm Community Member, 1 Post

Hi!

I'm wondering if it's possible to mass generate webpages somehow.

I want to be able to generate a lot of empty webpages with the help of a script.

I am very new to this, can someone help me with a basic example of how this would be done?

Thanks!

Avatar
Willr

20 September 2013 at 6:21pm Forum Moderator, 5511 Posts

You can generate pages on your site through PHP directly

$page = new Page();
$page->Title = "My Page";
$page->write(); // save the page

// publish it from draft to live
$page->doPublish('stage', 'live');

Avatar
jiggi89

27 September 2013 at 12:45am Community Member, 1 Post

Sorry if I use this thread to ask, but where would I put that PHP code to be able to generate the pages and make them appear in the sitetree?

/Jiggi

Avatar
Willr

27 September 2013 at 8:36pm Forum Moderator, 5511 Posts

Well it depends on where and what context you want to generate the page. Are you running a database migration from an existing system and therefore should encapsulate the code into a BuildTask [1], or perhaps you need to create a page by default (say always create 1 homepage object) then you'd put that code in a requireDefaultRecords call [2] which gets run when the user runs dev/build.

[1] http://api.silverstripe.org/2.4/class-BuildTask.html
[2] http://api.silverstripe.org/2.4/source-class-DataObject.html#3015-3040 (example https://github.com/silverstripe/silverstripe-cms/blob/3.1/code/model/SiteTree.php#L1382)