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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

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

Creating pages with default behaviours?


Go to End


3 Posts   2972 Views

Avatar
mmilo

Community Member, 9 Posts

20 November 2007 at 7:12pm

Hi I was just wondering if it was possible to create default behaviours for new pages. I am creating some custom pages and I would like for them to have 'show in menu' and 'show in search' turned off by default when they're created.

Avatar
Willr

Forum Moderator, 5523 Posts

20 November 2007 at 7:40pm

Edited: 20/11/2007 7:42pm

you can use $defaults array as a way of setting default values for a page type. Use it the same way as $db or $has_one eg in the Page class you can have

static $defaults = array(
'ProvideComments' => true
);

so to hide search and menus you could have

static $defaults = array (
'ShowInMenus' = false,
'ShowInSearch' = false
);

I think / hope thats the right names for the fields. More info on http://doc.silverstripe.com/doku.php?id=tutorial:2-extending-a-basic-site and http://doc.silverstripe.com/doku.php?id=datamodel

Avatar
mmilo

Community Member, 9 Posts

20 November 2007 at 10:04pm

Awesome thanks, I double checked the variable names in SiteTree.php and they seem correct so I anticipate that it will work a treat. Much appreciated.