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.

Data Model Questions /

Silverstripe: Show or hide pages on condition


Reply


348 Views

Avatar
Neelam

Community Member, 15 Posts

27 August 2013 at 3:27am

Edited: 27/08/2013 5:25pm

I am using silverstripe 3.0.0

Need to hide/show certain pages in the CMS tree view as well as list view and also all other places where they are displayed in the back end...like TreeDropDownFields etc.
This is based on a field value

I have tried by defining canView in Page.php but it doesn't work the way i want..

What worked for me was the following (added this code to an extension of SiteTree)

function augmentSQL(SQLQuery &$query) {
if(my condition here)
return;
else
$query->addWhere(where condition here);
}

Need to know if there is any better way than this....Any side effects of the above piece of code? Also need to add a filter for the Groups in the same way....