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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Best way to make a module extend from custom page type


Go to End


3 Posts   1466 Views

Avatar
Peavers

Community Member, 20 Posts

30 March 2015 at 11:04am

Edited: 30/03/2015 11:06am

My site structure is all custom page types with a single parent page the extends from Page.php.

class CustomPage extends Page {}

class  Custom_Controller extends Page_Controller {
    //load all javascript/css for entire site here etc
}


class SomeClass extends CustomPage {}

class SomeClass_Controller extends Custom_Controller
{
    // etc etc you get the point. 
}

Every other page in the site now extends from CustomPage and Custom_Controller respectively. Page.php is pretty much empty.

Now the problem comes when using modules that are not written internally. The Blog* module for example will not inherit the javascripts/css/functions defined in the new base class Custom_Controller is it is set to extend Page_Controller.

What is the ideal method here for basically making Blog_Controller extend Custom_Controller without modifying the Blog module?

*Blog module is just an example. this applies to all modules.

Avatar
Praxis Interactive

Community Member, 3 Posts

30 March 2015 at 12:27pm

Hi Peavers,

What I do is have a hidden parent class of Page called "BasePage". So BasePage extends SiteTree, and then the Page class in mysite/code extends BasePage (Page class uses $hide_ancestor to keep BasePage hidden from the CMS). I then include common requirements/functionality for all pages in BasePage. That way, any modules that extend Page can make use of these common elements included at the BasePage level. This approach has worked quite well for a number of projects.

Avatar
Peavers

Community Member, 20 Posts

30 March 2015 at 12:29pm

Thanks for the response and this is 'similar' to what we do, but due to our environment we must use Page.php as the BasePage and can't change this for various reasons.