Try our conversational search powered by Generative AI!

Exclude pages in PageTree

Vote:
 

Hi,

Is there a way to exclude pages from a standard EPiServer PageTree control? Let's say for example that I want to hide all pages of a certain page type. Is this possible? My scenario now is: I need to exclude two pages from the pagetree for all users except those who are accessing the web locally, from the web server. Can this be done, or do I need to develop my own PageTree control?

Thanks in advance!

/Mårten

#23680
Sep 12, 2008 15:37
Vote:
 

One way could be to hookup the LoadedChildren event from DataFactory and look for pages of "your" type in the ChildrenEventArgs.Items collection and remove them if the current request is not coming from the local webserver. Note though that this would remove the page's from _everywhere_, not just in the PageTree control.

However, if you tell us what you ultimately want to achieve we might come up with an alternate solution thats less "hackyish".

/johan

#23681
Sep 12, 2008 15:59
Vote:
 

Ok - some more details:

I have built a small EPi4.62-based web site. To the left on alla pages there is a left menu. It is implemented using EPiServer:PageTree. It can be used to navigate to all pages on the site. I would like to change this; there are two pages with sensitive content that should be available only if you are a local user i.e.

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString().Equals("127.0.0.1")

My plan was to solve this like this...

1) Introduce a new boolean page property "Only available for local users" on all pagetypes (or as a dynamic property)
2) Set this new property to "true" on the two pages with sensitive content
3) Change the code for the left menu so that it checks... (a) Is there a property "Only available for local users"? (b) If yes, is it set to "true"? - if YES: Do not show this page in the pagetree. Something like that.

My plan did not work because...

The pagetree control did not work as I expected. I thougt that it would be possible to set PageTree.DataSource = myPageDataCollection. Then I would be able to control which pages to include and which pages not to. The pagetree control does not, however, work like this. You can set a PageLink (or PageLinkProperty). But can you somehow control the datasource that it is bound to?

I hope that it is clear what I want to achieve.

Thanks!

/Mårten

#23691
Sep 12, 2008 16:57
Vote:
 

Hi Mårten.

Regarding your excluding pages problem, have you tired using the Filter for the PageTree? Here you can filter the PageDataCollection e.Pages.

PageTreeControl.PageLink = PageBase.Configuration.StartPage;

PageTreeControl.Filter += new FilterEventHandler(PageTreeControl_Filter);

PageTreeControl.DataBind();

private void PageTreeControl_Filter(object sender, EPiServer.Filters.FilterEventArgs e)
{
     // Do the filtering of the e.Pages collection
}

 

I don`t think there is a way to use a PageDataCollection as source for a PageTreeControl. But when I had the same problem, I used the asp:TreeView controller. And foreach PageData in the PageDataCollection, you create a treenode and add it to the TreeView.

foreach (PageData data in PageDataCollection)
{
    TreeNode node = new TreeNode();

   TreeView.Nodes.Add(node);

Then you can use the PageData properties to set the TreeNode properties. I don`t know if this is the best way to do it, but it solved my problem :)

 

BR,

Tore

#23703
Sep 13, 2008 12:40
Vote:
 

Filter e.Pages works like a charm. Thanks a lot!

 

#24141
Sep 25, 2008 11:21
Vote:
 

Small sidenote:

To iterate over the PageDataCollection in the filter method, you cannot use foreach, but instead, use for.

#62990
Nov 06, 2012 13:01
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.