London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

Display hidden pages in sitemap

Vote:
0

Does anyone have a simple solution to let the editor set that a page that is not VisibleInMenu to be shown in the sitemap when using a EPiServer:PageTree with EnableVisibleInMenu set to true. Not all "invisible" pages shnould be shown, only those that the editor sets (with a checkbox property on the page).

 

Is it possible when using this setup or do we have to iterate through the pages and use a standard asp:treeview?

#45843
Nov 19, 2010 12:21
Vote:
0

Hi Tobias,

I had to do something similar recently myself and i found the following article very helpful: http://www.epinova.no/blog/Kjetil-Simensen/dates/2010/4/extended-pagetree/

The method "CreateItemRecursive" is used to process each page and it is here you can filter the pages to display. The method uses a comma-separated string property to to filter out pagetypes but you can moify this "CreateItemRecursive" method to check the page[your_checkbox_propertyname] property instead. For your pages you could create a bool property called "IncludeInSiteMap" and filter as follows...

e.g.) Change the following:

foreach (string s in pagetypenames)
{
   if (s.Equals(page.PageTypeName, StringComparison.CurrentCultureIgnoreCase))
   {
         dontInclude = true;
         break;
   }
}
if(dontInclude) continue;

...to...


if (page["IncludeInSitemap"] == null) // or some similar check
{
     dontInclude = true;
     break;
}
                        
if(dontInclude) continue;

Hope that helps

#45854
Nov 19, 2010 15:14
Vote:
0

Add an event handler to the Filter event of the PageTree,

<EPiServer:PageTree runat="server" Filter="FilterVisibleInMenu" ...

In codebehind:

protected void FilterVisibleInMenu(object sender, EPiServer.Filters.FilterEventArgs e)
{
    for(int i = e.Pages.Count - 1; i--; i >= 0)
    {
        if (!e.Pages[i].VisibleInMenu && (e.Pages[i]["IncludeInSiteMap"] == null))
        {
            e.Pages.RemoveAt(i);
        }
    }
}

Or something like that (freehand code, could have logic and/or synax errors).

#45860
Nov 19, 2010 16:50
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.