Hjalmar Moa
Jan 12, 2011
  4918
(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
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024