Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Setting $showInMenus to false - or is it readonly?

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

Page: 1
Go to End
Author Topic: 2012 Views
  • rsouthgate
    Avatar
    Community Member
    10 Posts

    Setting $showInMenus to false - or is it readonly? Link to this post

    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

  • rsouthgate
    Avatar
    Community Member
    10 Posts

    Re: Setting $showInMenus to false - or is it readonly? Link to this post

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: Setting $showInMenus to false - or is it readonly? Link to this post

    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
    );

  • rsouthgate
    Avatar
    Community Member
    10 Posts

    Re: Setting $showInMenus to false - or is it readonly? Link to this post

    Perfect. Thank you.

    2012 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.