Try our conversational search powered by Generative AI!

Hjalmar Moa
Jan 12, 2011
  4883
(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
The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024

The Experimentation Process

This blog is part of the series -   Unlocking the Power of Experimentation: A Marketer's Insight. Welcome back, to another insightful journey into...

Holly Quilter | May 16, 2024

Azure AI Language – Sentiment Analysis in Optimizely CMS

In the following article, I showcase how sentiment analysis, which is part of the Azure AI Language service, can be used to detect the sentiment of...

Anil Patel | May 15, 2024 | Syndicated blog

Optimizely Data Platform Visitor Groups now supports multiple instances

The module V2.0 now supports multiple Optimizely Data Platform instances, allowing personalized content based on real-time segments and profile dat...

Andrew Markham | May 15, 2024 | Syndicated blog

IP block for edit and admin in DXP

Why IP-blocking edit/admin? A hacker can try to guess user names and passwords to gain access to your site. This risk can be minimized in a couple ...

Daniel Ovaska | May 15, 2024