The following explanation describes pages, properties, page types and page templates.
- A page is an instance of the .NET class that defined the page type.
- A page type defines a set of properties.
- When you create a page, you assign values to the properties defined by the page’s page type.
- When a page is viewed by a visitor, the page template associated with the page’s page type generates the output that is sent to the client.
Page type
During initialization, EPiServer CMS scans binaries in the bin folder for .NET classes that inherit PageData, as shown in the following example. EPiServer creates a page type for each of the found classes and creates a corresponding property on the page type for public properties on the .NET class.
C#
[ContentType]
public class NewsPageModel : PageData
{
public virtual XhtmlString MainBody { get; set; }
}
You also can create page types without a corresponding .NET class.
Page types implicitly contain a set of built-in properties which are available for pages, regardless of the page type instance. See the PageData.Property property for a list of built-in properties.
Page template
You can create page templates in EPiServer CMS using web forms or ASP.NET MVC, examples here are based on Web Forms.
A page template generates output for pages of a given type, often as an aspx type of file. You can use a page template for more than one page type but a one-to-one connection is the most common approach. When you create a page template, use any combination of markup, server controls, code behind logic and more. The following example shows a template for a page.
C#
public class NewsPage : TemplatePage<NewsPageModel>
{
protected override void OnLoad(System.EventArgs e)
{
string mainBody = CurrentPage.MainBody.ToHtmlString();
}
}
A page template accesses the property values of the page that was requested by the client to integrate the values into the output by using base classes and User Controls within the EPiServer CMS API; a chain of base classes from which your web form can inherit; 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>.
If you do not define your pages in code by .NET classes, use the untyped versions PageBase, TemplatePage, UserControlBase and PageControllerBase.
When you make 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. 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, access rights, and so on. The value of CurrentPage is automatically set to the PageData object that is requested by the client; you do not have to find out what page you should be fetching property values from yourself; you only need to consume the property values from the CurrentPage object.
Related topics
Do you find this information helpful? Please log in to provide feedback.