Take the community feedback survey now.

Alexander Haneng
Aug 30, 2012
  14908
(0 votes)

How to define Page Types in EPiServer 7 CMS - A quick reference

This blog post is a quick reference on how to define page types in code in EPiServer 7 CMS.

 

Updated to EPiServer 7 CMS on 14.01.2013

This blog post was originally written for a preview version of EPiServer 7 CMS, but is now updated to the final release version.

 

Creating a new page type

To create a new page type you need two things:
1. a page type class (.cs)
2. a page template (.aspx)

If you are new to creating EPiServer 7 page types start by reading How to create a simple Page Type in code for EPiServer CMS 7 first.

 

 

The page type class

The first part of a new page type is creating a page type class(.cs)  that inherits from PageData

 

MyPage.cs

using System.ComponentModel.DataAnnotations;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.DataAnnotations;
 
namespace EPiServer.Templates.Alloy.Models.Pages
{
    [ContentType(DisplayName = "MyPage")]
    public class MyPage : PageData
    {
        [Display(
            Name = "My name",
            Description = "",
            GroupName = SystemTabNames.Content,
            Order = 1)]
        public virtual string MyName { get; set; }
    }
}

 

 

The page template page

To display your page type you need a template page (.aspx).

 

MyPageTemplate.aspx

<%@ Page Language="c#"
    Inherits="EPiServer.Templates.Alloy.Views.Pages.MyPageTemplate" 
    CodeBehind="MyPageTemplate.aspx.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>My Page Template</title>
</head>
<body>
<form id="Form1" runat="server">
<div>
<EPiServer:Property runat="server" PropertyName="MyName" />
</div>
</form>
</body>
</html>

 

You need to link the page type class to the template in the code behind file (.aspx.cs) by referencing the right class (MyPage).

 

MyPageTemplate.aspx.cs

using EPiServer.Framework.DataAnnotations;
using EPiServer.Templates.Alloy.Models.Pages;
 
namespace EPiServer.Templates.Alloy.Views.Pages
{
    [TemplateDescriptor(Path = "~/Views/Pages/MyPageTemplate.aspx")]
    public partial class MyPageTemplate : EPiServer.TemplatePage<MyPage>
    {
    }
}

 

 

 

Page Type Properties

This is the code needed to define a string property on the page type:

[Display(
    Name = "My name",
    Description = "",
    GroupName = SystemTabNames.Content,
    Order = 1)]
public virtual string MyName { get; set; }

 

See the EPiServer 7 property quick reference on how to define other property types

 

 

Adding a local Block to a Page Type

Adding a block to a page type is similar to adding a property. If you have the block MyBlock you add it to the page type like this:

[Display(
    Name = "Contact person",
    Description = "",
    GroupName = SystemTabNames.Content,
    Order = 2)]
public virtual MyBlock ContactPerson { get; set; }

 

You also need to add the block to the page template:

<EPiServer:Property runat="server" PropertyName="ContactPerson" />

 

How to create a simple block type in EPiServer 7

 

 

Adding a Content Area for Shared Blocks

If you want the page type to have an area where the editor can add “shared blocks” you need a ContentArea property:

[Display(
    Name = "Right block area",
    Description = "",
    GroupName = SystemTabNames.Content,
    Order = 3)]
public virtual ContentArea RightBlockArea { get; set; }

 

You also need to add the content area to the page template:

<EPiServer:Property PropertyName="RightBlockArea" runat="server" />

 

 

ContentType Attribute

The available ContentType attributes are:

Property name: Description: Default:
AvailableInEditMode Can new pages be of this type be created by the editors true
Description Text description to show in edit mode null
DisplayName The name in edit mode for the page type null
Order Sort index 100
GUID Unique identifier Guid.Empty
Group name Name for grouping page types null

 

[ContentType(
    DisplayName = "MyPage", 
    Description = "",
    GUID = "7E94EB59-1F75-4502-B3A9-ADB6BD671CFF",
    AvailableInEditMode = true,
    Order = 1,
    GroupName = "AlloyTech")]
public class MyPage : PageData

 

 

Access Attribute

Defines who has access to create pages of this type.

Attribute name: Description: Default:

Access(
Users=...,
Roles=...,
VisitorGroups=...)

Defines who has access to create a new page of this type. Role Everyone

 

[Access(Users = "haneng", Roles="CmsEditors")]
   public class MyPage : PageData

 

 

ImageUrl Attribute

The attribute ImageUrl can be used to set the icon for a page type.

[ImageUrl("~/Templates/AlloyTech/Images/StartPageTypeIcon.png")]
public class StartPage : AlloyPage

 

image

 

 

 

AvailablePageTypes Attribute

You can define in code where the new page type can be created using the AvailablePageTypes attribute.

 

Property name: Description: Default:
Availability Defines if all or none page types should be available. If none is set other settings on the attribute is ignored. Availablity.All
Include A type array of typed pages to specify which page types that should be available under a page instance of the type with the attribute. Type[0]
Exclude A type array of typed pages to specify which page types that should not be available under a page instance of the type with the attribute. Type[0]
IncludeOn States that the page with this attribute should be available under the all the typed pages in the type array. Type[0]
ExcludeOn States that the page with this attribute should be not available under the any of the typed pages in the type array. Type[0]

IncludedOn differs from Include in the way that it is not excluding. That is for types in IncludedOn that has all page types available no page types will be excluded. Include on the other hand will exclude all typed pages except the ones given in Include.

 

[AvailablePageTypes(Include = 
    new Type[] {typeof(StandardPage), typeof(StartPage)})]
public class MyPage : PageData

 

 

 

TemplateDescriptor Attribute

The [TemplateDescriptor] attribute can be used on templates to add meta data to the template. The attribute can also be used to set the template as the default template for the page data.

Property Name: Description: Default:
Path The path to the template to be rendered. Needs to be set if folder structure does not follow namespace structure. null
ModelType The page data type. This can be set on an untyped template which derives from EPiServer.TemplatePage to set the page data type, which will be the type of the CurrentPage. null
Default Defines the template as the default template for this page type. false
Description Description of the template. null
Inherited Inherited means that when this property is set to true, all page data types, which inherits from the ModelType type/Generic type will get the template as a supported template. false

 

[TemplateDescriptor(
    Path = "~/Templates/AlloyTech/Pages/MyPageTemplate.aspx", 
    ModelType = typeof(StandardPage), 
    Default = true, 
    Description = "", 
    Inherited = true
    )]
public partial class MyPageTemplate : EPiServer.TemplatePage<MyPage>

 

 

The EPiServer SDK

A lot of this information is from the excellent EPiServer SDK.

Aug 30, 2012

Comments

Please login to comment.
Latest blogs
A day in the life of an Optimizely OMVP - Opticon London 2025

This installment of a day in the life of an Optimizely OMVP gives an in-depth coverage of my trip down to London to attend Opticon London 2025 held...

Graham Carr | Oct 2, 2025

Optimizely Web Experimentation Using Real-Time Segments: A Step-by-Step Guide

  Introduction Personalization has become de facto standard for any digital channel to improve the user's engagement KPI’s.  Personalization uses...

Ratish | Oct 1, 2025 |

Trigger DXP Warmup Locally to Catch Bugs & Performance Issues Early

Here’s our documentation on warmup in DXP : 🔗 https://docs.developers.optimizely.com/digital-experience-platform/docs/warming-up-sites What I didn...

dada | Sep 29, 2025

Creating Opal Tools for Stott Robots Handler

This summer, the Netcel Development team and I took part in Optimizely’s Opal Hackathon. The challenge from Optimizely was to extend Opal’s abiliti...

Mark Stott | Sep 28, 2025

Integrating Commerce Search v3 (Vertex AI) with Optimizely Configured Commerce

Introduction This blog provides a technical guide for integrating Commerce Search v3, which leverages Google Cloud's Vertex AI Search, into an...

Vaibhav | Sep 27, 2025

A day in the life of an Optimizely MVP - Opti Graph Extensions add-on v1.0.0 released

I am pleased to announce that the official v1.0.0 of the Opti Graph Extensions add-on has now been released and is generally available. Refer to my...

Graham Carr | Sep 25, 2025