November Happy Hour will be moved to Thursday December 5th.

Hjalmar Moa
Jan 12, 2011
  4977
(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
Optimizely SaaS CMS + Coveo Search Page

Short on time but need a listing feature with filters, pagination, and sorting? Create a fully functional Coveo-powered search page driven by data...

Damian Smutek | Nov 21, 2024 | Syndicated blog

Optimizely SaaS CMS DAM Picker (Interim)

Simplify your Optimizely SaaS CMS workflow with the Interim DAM Picker Chrome extension. Seamlessly integrate your DAM system, streamlining asset...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Optimizely CMS Roadmap

Explore Optimizely CMS's latest roadmap, packed with developer-focused updates. From SaaS speed to Visual Builder enhancements, developer tooling...

Andy Blyth | Nov 21, 2024 | Syndicated blog

Set Default Culture in Optimizely CMS 12

Take control over culture-specific operations like date and time formatting.

Tomas Hensrud Gulla | Nov 15, 2024 | Syndicated blog

I'm running Optimizely CMS on .NET 9!

It works 🎉

Tomas Hensrud Gulla | Nov 12, 2024 | Syndicated blog

Recraft's image generation with AI-Assistant for Optimizely

Recraft V3 model is outperforming all other models in the image generation space and we are happy to share: Recraft's new model is now available fo...

Luc Gosso (MVP) | Nov 8, 2024 | Syndicated blog