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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Silverstripe: Show or hide pages on condition


Go to End


1147 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....