Jump to:

23545 Posts in 19310 Topics by 2888 members

General Questions

SilverStripe Forums » General Questions » Hide pages from site map.

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
Go to End
Author Topic: 1412 Views
  • micahsheets
    Community Member
    164 Posts

    Hide pages from site map. Link to this post

    I have created a site map based on the tutorial. This site map works great. I want to add a checkbox to the CMS that will hide a page from the site map. I see that currently I can do it by page type like the tutorial hides the error page. However I want to be able to click a checkbox on any page to hide it. I have added

    'HideInSiteMap' => 'Boolean' to the $db array and

    $fields->addFieldToTab("Root.Behaviour", new CheckboxField("HideInSiteMap", "Hide from site map?"),'ShowInSearch'); to getCMSFields in the Page class.

    This works and creates a table called Page which puts the page ID next to the ideInSiteMap column and does put a 1 or 0 depending on the value of the checkbox in CMS.

    So far this all works as I had expected.

    Now in the sitemap.php file I cannot figure out how to access the HideInSiteMap values in the Page table.

    I tried

    if(!($page instanceof ErrorPage) && $page->Title != $this->Title && $page->HideInSiteMap != 1)

    But $page->Title works because it is getting that from the sitetree table not the page table.

    So how do I access the page table?

  • Hamish
    Community Member
    712 Posts

    Re: Hide pages from site map. Link to this post

    That should work.

    Don't worry too much about what tables are created. the sapphire ORM looks after table creation and won't make a Page table until it needs to. The Page table didn't exist before because it didn't need to add any more fields to the data class (since $db was empty).

    Put it this way - Page is a type of SiteTree - so when you get a page, the ORM gets the SiteTree record, and adds the fields it *also* finds in the Page table. The Page table just adds fields that you define in Page.php (in $db), but retains all the properties and methods of SiteTree too

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.