Try our conversational search powered by Generative AI!

Hjalmar Moa
Jan 12, 2011
  4880
(0 votes)

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. :)

Jan 12, 2011

Comments

Anders Hattestad
Anders Hattestad Jan 12, 2011 08:21 PM

you could also do it like this
public partial class Test : SystemPageBase
{
}

But your code makes it easy to change the default page thou

Hjalmar Moa
Hjalmar Moa Jan 13, 2011 08:33 AM

Anders: I like that way, but it somwhow feels odd to use a System page for display, and not just for administrative stuff. On the other hand, naming should not stand in the way for putting it to great use. Your way is better since it hooks up other stuff such as the translations in surrounding code like the UserControlBase. Thanks for the tip.

Hjalmar Moa
Hjalmar Moa Feb 9, 2011 01:12 PM

Using SystemPageBase seem to have some unexpected downsides when creating customer facing pages. Like textboxes getting class="episize240" added. I think Ill go back to using my original base page and take the consequesces.

Please login to comment.
Latest blogs
Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024

Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024