Try our conversational search powered by Generative AI!

fredriktjarnberg
Aug 18, 2009
  6385
(1 votes)

The lost EPiServer.TypedPageBase<PageData>

When CMS 5 R2 SP2 was in RC, it included a type to simplify using your own PageData types when building page templates. Before the release we decided to remove this class for two reasons: naming and whether or not it is OK to hide the CurrentPage property of PageBase (I think it is, btw).

What should you do if you need this type in your EPiServer project?

For those using the PageTypeBuilder project there is a replacement that should be used instead, TemplatePageBase.

However, if you for some reason still want to use the original TypedPageBase here’s the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Core;
using EPiServer.Web.PageExtensions;

namespace EPiServer
{
    /// <summary>
    /// Page Template class for supporting strongly typed PageData objects with an arbitrary type <typeparamref name="TPageData"/>.
    /// </summary>
    /// <typeparam name="TPageData">The strongly typed PageData type.</typeparam>
    public class TypedPageBase<TPageData> : PageBase
        where TPageData : PageData, new()
    {
        /// <summary>
        /// Creates a new instance of <see cref="TypedPageBase"/> with a default set of features enabled.
        /// </summary>
        public TypedPageBase() : this(
            SiteRedirect.OptionFlag | 
            ContextMenu.OptionFlag | 
            PageStatistics.OptionFlag | 
            SaveCurrentPage.OptionFlag, 0) { }

        /// <summary>
        /// Creates a new instance of <see cref="TypedPageBase"/> where individual features can be enabled and disabled.
        /// </summary>
        /// <param name="enable">The bitmask for enabling certain features.</param>
        /// <param name="disable">The bitmask for disabling certain features.</param>
        public TypedPageBase(int enable, int disable) : base(enable, disable) { }

        private TPageData _currentPage;
        /// <summary>
        /// Gets a strongly typed PageData of type <typeparamref name="TPageData"/>.
        /// </summary>
        public virtual TPageData CurrentTypedPage
        {
            get
            {
                if (_currentPage == null)
                {
                    _currentPage = PageData.ShallowCopy<TPageData>(base.CurrentPage);
                }
                return _currentPage;
            }
        }
    }
}

In the latest version of Page Type Tool the corresponding generated code looks like this:

    /// <summary>
    /// A base class for page template implementations.
    /// </summary>
    /// <typeparam name="TPageData">A PageData class that will represent the content class for the page template.</typeparam>
    public class PageBase<TPageData> : EPiServer.PageBase
        where TPageData : EPiServer.Core.PageData, new ()
    {
        private TPageData _currentPage;
        /// <summary>
        /// Creates an instance of the PageBase type.
        /// </summary>
        public PageBase() : 
                this((EPiServer.Web.PageExtensions.SiteRedirect.OptionFlag 
                                | (EPiServer.Web.PageExtensions.ContextMenu.OptionFlag 
                                | (EPiServer.Web.PageExtensions.PageStatistics.OptionFlag | EPiServer.Web.PageExtensions.SaveCurrentPage.OptionFlag))), 0)
        {
        }
        /// <summary>
        /// Creates an instance of the PageBase type with specified page feature configuration.
        /// </summary>
        /// <param name="enable">The page options to enable.</param>
        /// <param name="disable">The page options to disable.</param>
        public PageBase(int enable, int disable) : 
                base(enable, disable)
        {
        }
        /// <summary>
        /// Gets page data for the current page.
        /// </summary>
        public new virtual TPageData CurrentPage
        {
            get
            {
                if ((this._currentPage == null))
                {
                    this._currentPage = EPiServer.Core.PageData.ShallowCopy<TPageData>(base.CurrentPage);
                }
                return this._currentPage;
            }
        }
    }
The most notable difference is the type name and that it hides the CurrentPage property implementation of the base class.
Aug 18, 2009

Comments

Sep 21, 2010 10:32 AM

Hey Fredrik!
I'm not familiar with what the option constructor parameter does exactly. Is the options you are using (SiteRedirect.OptionFlag | ContextMenu.OptionFlag | PageStatistics.OptionFlag | SaveCurrentPage.OptionFlag) the combination you would recommend for Page Type Builders TemplatePage/EditPage/etc classes aswell?
/ Joel Abrahamsson (joel.abrahamsson@nansen.se)

Sep 21, 2010 10:32 AM

The options passed in the default constructor matches the options used for TemplatePage (which can be visualized with your favourite disassembler). So in essence using those parameters you will have the same functionality as provided by TemplatePage without the need to inherit the whole hierarchy. If you study the inheritance in detail you will find that EditPage adds a few APIs for working with script and css files which you will loose by using the PageBase implementation shown above.

The idea was to have one "small" class that provides the generic extension to PageBase instead of four.

Please login to comment.
Latest blogs
The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024

What's new in Language Manager 5.3.0

In Language Manager (LM) version 5.2.0, we added an option in appsettings.json called TranslateOrCopyContentAreaChildrenBlockForTypes . It does...

Quoc Anh Nguyen | Apr 15, 2024

Optimizely Search & Navigation: Boosting in Unified Search

In the Optimizely Search & Navigation admin view, administrators can set a certain weight of different properties (title, content, summary, or...

Tung Tran | Apr 15, 2024

Optimizely CMS – Getting all content of a specific property with a simple SQL script

When you need to retrieve all content of a specific property from a Page/Block type, normally you will use the IContentLoader or IContentRepository...

Tung Tran | Apr 15, 2024

Join the Content Recommendations Work Smarter webinar May 8th 16.00-16.45 CET with expert Aidan Swain

Learn more about Content Recommendations, with Optimizely’s very own Senior Solutions consultant, Aidan Swain . He will discuss best practices and...

Karen McDougall | Apr 12, 2024