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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Data Model Questions /

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

Silverstripe: Show or hide pages on condition

Go to End



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 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)
$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....