Setting custom default records during installation

Hi,
Initial installation comes with default pages (Home, About Us, Contact). I would like to create my own default page and post records during installation and build. I see that there is a SiteTree.php file that contains the requireDefaultRecords() function in the Vendor folder. Is it possible to include or override this within my project? What would be the best way to acheive this?

As stated in the official documentation, you can overload that method to store whatever you want in the database.

If you do not want the default pages to be created, you can set create_default_pages to false (never done that but it should work). Add this to your YAML:

SilverStripe\CMS\Model\SiteTree:
    create_default_pages: false

Hi,
thank you for the tip. It works. :slight_smile:
I put my code in app/src/myVendor/initialContent.php
I was wondering if there is a “better” place for this?
BR, Bagus

requireDefaultRecords() is a DataObject method: to me this is a clear indication the implementor want you to create instances of the model you are extending, i.e. on Page you should create pages. Also, this probably ensures that the relevant table is created before inserting default records in the really first dev/build call.

This is a convention though and (as Morpheus says) some rules can be bend, others can be broken.

I see,
I’m more used to Laravel, where I used “migrations”…
Anyway the documentation says: “This function is called whenever the database is built, after the database tables have all been created”. But just to be on the safe side I will add checks if DB tables have been created.
Thnx for your help.