Jump to:

23007 Posts in 11866 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » How to hide a page type from CMS

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 4125 Views
  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: How to hide a page type from CMS Link to this post

    No, I don't suppose it is 'the' way to do this - it's too weird to have to create a page only to remove it again - just to get rid of the parent as wel. But it did work and I hadn't found another way yet...

  • martimiz
    Avatar
    Forum Moderator
    1038 Posts

    Re: How to hide a page type from CMS Link to this post

    Ok, to be complete - feeling a bit guilty I guess : the preferred way would probably be to use the canCreate() method. Just adding it to your custom MyPage class and having it return false, would remove it from the dropdown:

    class MyPage extends Page {

       function canCreate($Member = null) {
          return false;
       }
       ...

    Because this would now prevent any user, even the admin, from creating a page of this type, you'd need to build in some conditional. One way to do this, is to create a new permission code within the SecurityAdmin, and check that against the current user.

    Check out http://www.ssbits.com/snippets/2009/create-a-permission-code/ for how to create and work with permissions.

    I experimented with a (simple) bit of code, where you can define a list of 'restricted' pagetypes using an array from _config.php. If anyone is interested, I'll add a link...

  • svandragt
    Avatar
    Community Member
    43 Posts

    Re: How to hide a page type from CMS Link to this post

    I created a ProtoPage that extends SiteTree and altered Page to extend from ProtoPage. This allows me to put all base functionality in ProtoPage.

    To stop ProtoPage from showing up in the new menu, add the following line to mysite/_config.php (SS 3.0.5):

    SiteTree::$hide_ancestor = 'ProtoPage';

    Note it's not good practice to set variables directly, but there is no set_hide_ancestor. I assume it's recommended to set the hide_ancestor attribute on individual page types, however you then have to ensure that any page type that inherits sets the value back to the value in SiteTree (null).

    4125 Views
Page: 1 2
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.