volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Modify data in PageTreeData

We need to modify which pages to be shown in a PageTree control. Some of the pages should not be shown according to some rules. Is it possible to get the children pages and remove some of them from the control? /Björn
#12851
Nov 29, 2006 9:03
Sure, you can either apply a filter to the control, or create your own DataSource where you populate your own PageDataCollection. The filter alternative is prettier and more cache-friendly, so I would go with that. Here's an example where a certain page type is removed from the collection: private void Page_Load(object sender, System.EventArgs e) { MyPageTree.Filter += new FilterEventHandler(MyPageTree_Filter); } private void MyPageTree_Filter( object sender, EPiServer.Filters.FilterEventArgs e) { PageDataCollection pdc = e.Pages; for(int i=0; i< pdc.Count; i++) { if(pdc[i].PageTypeName.Equals("PageType to remove")) { pdc.RemoveAt(i); i--; } } } There is a technical preview in the library called "Implementing Filters in EPiServer" for further reference. /Marten
#14992
Nov 29, 2006 10:16
I tried to implement exactly what you suggested, but I can't get the event handler to work. I doesn't reach the code in the event method - like this (submenu is a PageTree control). If I do the same thing with a PageList it works fine. Shouldn't it work in a PageTree control? protected void Page_Init (object sender, EventArgs e) { submenu.Filter += new FilterEventHandler(submenu_Filter); } public void submenu_Filter (object sender, EPiServer.Filters.FilterEventArgs e) { PageDataCollection pdc = e.Pages; pdc.RemoveAt(0); } /Björn
#14993
Nov 29, 2006 13:48
Hm, that is strange. I have no direct answer to that, as I thought that would work fine. How about this then: Wrap the item content in to a panel which you decide should be visible or not in a code-behind function, here titled IsVisible which should return a boolean value. If it will be set to false, the inside content of the panel will not be rendered.
#14994
Nov 29, 2006 14:36
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.