This content is archived. See latest version here

Last updated: Mar 31 2014

This section contains information about the most central concept of an EPiServer CMS project, namely that of pages, properties, page types and page templates.

It works in the following way:

  • A page type defines a set of properties.
  • A page is an instance of the .NET class that defined the page type.
  • When creating a page the editor assigns values to the properties defined by the page’s page type.
  • When a page is requested by a visitor, the page template associated with the page’s page type is used to generate output.

Page type

During initialization EPiServer CMS will scan all binaries in the bin folder for .NET classes that inherits PageData as example below. For each of the found classes a page type is created and for all public properties on the .NET class a corresponding property on the page type will be created.

C#
[ContentType]
public class NewsPageModel : PageData
{
    public virtual XhtmlString MainBody { get; set; }
}

Refer to the Block types and templates for a description of blocks which can be used as a reused building block when creating pages.

It is also possible to create page types without an corresponding .NET class.

In addition to the list of properties added by the developer all page types implicitly contains a set of built-in properties. These built-in properties are always available for all pages regardless of which page type they are instances of. For a full list of built-in properties please see the documentation for the PageData.Property property.

Page template

A page template is used to generate output for pages of a give type, often as an aspx type of file. Page templates in EPiServer CMS can be created using web forms or ASP.NET MVC. A page template can be used for more than one page type but a one-to-one connection is the most common approach. When creating a page template with web forms or MVC, you can use any combination of markup, server controls, code behind logic and more. Below is an example of a template for a page.

C#
public class NewsPage : TemplatePage<NewsPageModel>
{
    protected override void OnLoad(System.EventArgs e)
    {
        string mainBody = CurrentPage.MainBody.ToHtmlString();
    }
}

A central function of any page template is to access the property values of the page that was requested by the client so that they can be integrated into the output, so how do you accomplish that? This is where the base classes and User Controls come into play. In the following you will find an example based on a web form page template.

Within the EPiServer CMS API there is a chain of base classes that your web form can inherit from, but TemplatePage<T> is the most common selection. The corresponding base class for User Controls is UserControlBase<T> and for MVC controllers it is EPiServer.Web.Mvc.PageControllerBase<T>.

There are also untyped versions PageBase, TemplatePage, UserControlBase and PageControllerBase available if you do not define your pages in code by .NET classes.

The TemplatePage inheritance chain

By making your own web forms and User Controls inherit from the appropriate base classes within the EPiServer CMS API you gain access to a set of methods and properties that integrate your web form with EPiServer CMS. We will not discuss these methods and properties in detail in this article, but we will highlight one of them; the CurrentPage property.

Access to the CurrentPage property is probably the most important benefit you get from inheriting from TemplatePage<T> (or TemplatePage for untyped pages). You will find yourself accessing this property many times when you are writing web forms and User Controls for an EPiServer CMS project. So what is it? The type of the CurrentPage property is an instance of your .NET class that inherits EPiServer.Core.PageData (or PageData for untyped pages). A PageData object is the programmatic representation of a page in EPiServer, it contains the properties defined in your .NET class but also access rights etc. The value of CurrentPage is automatically set to the PageData object that is requested by the client. This means that you do not have to find out what page you should be fetching property values from yourself, all you need to do is consume the property values from the CurrentPage object.

Page

The page is where the page type and the page template comes together. The editor creates the page and sets the values for the properties defined by the page’s page type. When the page is requested by a visitor the page template will be used to create the output to be sent to the client.

See also


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/