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.

General Questions /

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

Hide pages from site map.


Reply


2 Posts   1522 Views

Avatar
micahsheets

Community Member, 165 Posts

15 January 2009 at 12:15pm

Edited: 15/01/2009 12:58pm

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?

Avatar
Hamish

Community Member, 712 Posts

15 January 2009 at 2:43pm

Edited: 15/01/2009 2:44pm

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