Using properties on pages not in EPiServer
Sometimes I’ve had some use for a page on a site which isn’t a EPiServer page. Some pages should just be used once or a page that the editor shouldn’t touch. I found a use for it when I had to create a password recovery page. I couldn’t see a benefit in having it cluttering the page tree.
The problem comes when we want to use the master page from our site which uses properties or page listings. The problem is that the properties don’t know which page you are on, since you aren’t on an episerver page. The solution is to inherit from a base page like the following, or just to implement in on the page itself.
public class EPiServerContextPageBase : Page, ICurrentPage, IPageSource
{
public EPiServerContextPageBase()
{
CurrentPage = DataFactory.Instance.GetPage(PageReference.StartPage);
}
private PageData currentPage;
public EPiServer.Core.PageData CurrentPage
{
get
{
return currentPage;
}
set
{
currentPage = value;
}
}
public PageDataCollection GetChildren(PageReference pageLink)
{
return DataFactory.Instance.GetChildren(pageLink);
}
public PageData GetPage(PageReference pageLink)
{
return DataFactory.Instance.GetPage(pageLink);
}
}
These interfaces creates a context for properties and lists to work.
I hope you found it useful. :)
Comments