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   382 Views

Avatar
mantasia12

Community Member, 1 Post

19 September 2013 at 9:58pm

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

Forum Moderator, 5513 Posts

20 September 2013 at 6:21pm

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

Community Member, 1 Post

27 September 2013 at 12:45am

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

Forum Moderator, 5513 Posts

27 September 2013 at 8:36pm

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)