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

Setting $showInMenus to false - or is it readonly?


Go to End


4 Posts   3725 Views

Avatar
rsouthgate

Community Member, 12 Posts

2 September 2009 at 4:41pm

Hi,
I would like to make sure that all pages created of a particular template type are not shown in menus. Is it possible to set this value from the Page_Controller and then remove the checkbox / make the checkbox disabled so that users cannot make this page visible in menus?
Thanks
Robin

Avatar
rsouthgate

Community Member, 12 Posts

2 September 2009 at 5:06pm

Just to clarify - this is what I've got so far:

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeFieldFromTab('Root.Behaviour', 'ShowInMenus')
$fields->dataFieldByName('ShowInMenus')->setValue(0);
return $fields;
}

which hides the field ok, but I can't seem to set the value to 0

Avatar
Willr

Forum Moderator, 5523 Posts

2 September 2009 at 7:04pm

You can set the default value of the field using static $defaults. Then remove the field as you have done.

// on your custom page type
static $defaults = array(
'ShowInMenus' => 0
);

Avatar
rsouthgate

Community Member, 12 Posts

3 September 2009 at 9:24am

Perfect. Thank you.