How To Create Pages as Part of a Deployment?

Silverstripe Version:


I have a silverstripe based web application which is under active development and gets deployed regularly to our dev, QA, UAT etc environments. At the moment we have automated jobs for those deployments which copy the files, do a composer install and run dev/build all from the command line so that my development changes can easily be deployed to our various environments.

What is missing is that when I create a new page, I have to manually go to the environment after deployment and log in to to /admin Pages -> Add New -> Select Page Type -> Fill in the form and click Publish.

Is there a way to automate that process? I cannot find any info in the docs or anything in the code which defines that these pages exist - do they exist solely in the database? The Page names and paths are always the same since other parts of our app need to know where to point to in order to function.

Thanks in advance,

Hi, sounds like you’re after defaultRecords SilverStripe\CMS\Model\SiteTree | SilverStripe API

So on your CustomPage class

public function requireDefaultRecords() {
  if (  /*check if custom class doesn't exist or by title etc */ ) {
    $page = CustomPage::create();
    $page->Title = 'A page';
    $page->Content= 'some content';
    // etc.

The new records will be created on dev/build

This is perfect. Thank you!