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.

Customising the CMS /

Setting $showInMenus to false - or is it readonly?


Reply


4 Posts   2155 Views

Avatar
rsouthgate

Community Member, 10 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, 10 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, 5513 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, 10 Posts

3 September 2009 at 9:24am

Perfect. Thank you.