SilverStripe's excellent pagetypes practice

Imagine you have two options: Page and Home . Obviously, the Page will serve as the main page type for all pages, and HomePage for the main page only. For each base page, you need a custom header photo, but not for the main page.

What would be the perfect setting, as in best practice?

The page is extends sitetreeand has an ImageUpload field for the title

HomePage extends Pageand disables the ImageUpload field for the header

OR

The page is extends sitetreeand has an ImageUpload field for the title

HomePage extends sitetreewithout any additional CMS fields

+4
source share
2 answers

You can create another type of page that inherits the page. Let me call it "BasicPage".

The home page directly inherits the page.

BasicPage also directly inherits the page.

Then attach the "has_one" image to BasicPage.

"" . "", . , , , , , , , . , , , . , .

+2

:

page.php

Page , Page, .

class Page extends SiteTree {

    private static $has_one = array(
        'Image' => 'Image'
    );

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main', UploadField::create('Image'), 'Content');
        return $fields;
    }

}

HomePage.php

, , $fields->removeByName('Image');

class HomePage extends Page {

    private static $db = array();

    public function getCMSFields() {

        $fields = parent::getCMSFields();

        $fields->removeByName('Image');

        return $fields;
    }
}
+4

All Articles