Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Alexander Haneng
Aug 8, 2012
(5 votes)

How to create a Page Type in code for EPiServer CMS 7

In EPiServer 7 CMS you can defined page types in code. In this blog post we cover how to create your first page type in this way.


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.


A simple page type

A page type in EPiServer 7 CMS consists of two parts:

1. A page type class (.cs) that defines what properties the page should contain

2. A page template (.aspx) that renders the page and those properties.


Creating a page type class

Here is a simple page type class that defines our page type MyPage:



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
            Name = "My name",
            Description = "",
            GroupName = SystemTabNames.Content,
            Order = 1)]
        public virtual string MyName { get; set; }

MyPage has a single string property called MyName.

Here is a quick reference on how to define the other property types in EPiServer 7, like XhtmlString, LinkCollection and Number


Creating a page template

We now need a page template that can render pages of our page type MyPage.



<%@ Page Language="c#" 
    CodeBehind="MyPageTemplate.aspx.cs" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="">
<head id="Head1" runat="server">
<title>My Page Template</title>
<body style="background-color: white;">
<form id="Form1" runat="server">
<h1>MyPage Template</h1>    
My name is
<EPiServer:Property runat="server" PropertyName="MyName" />


In the code behind for the aspx file we set the connection between the page type class and the page template by setting TemplatePage<MyPage> (where MyPage is our page type class.)



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>


Using our new page type

After building the project and starting our EPiServer 7 site again we will see the new page type in admin mode:



The page type is also available in edit mode when we click create a new page:


(If you are using the Alloy demo and can’t see the MyPage as a page type when you create a new page, try creating a new page under the “Alloy Track” page instead as the start page has some restrictions set)


Lets create a new page of the type MyPage and enter “Alexander” into the MyName property:



After we publish the page the visitors will see this page:



That was how to create your first page type in EPiServer 7 from code. The next step is to create a simple block type.

Aug 08, 2012

Comments Dec 25, 2012 12:26 AM

Hi Alexandar,

Its nice article, We have two different offices on two different locations and both teams use TFS and check in the code togather. What will be the best way as if one developer creates some page type and enter data for that same page with data should also be available in next office?


Jan 14, 2013 10:12 AM

Hi Khurram,

That is a difficult problem. You will need to have a schedule for when people can commit changes to page and block types, and get everyone to be on the same version.

Grzegorz Jeremias
Grzegorz Jeremias May 20, 2013 09:15 AM


There is a nice article about synchronization of typed models

Dan Le
Dan Le Aug 19, 2013 07:55 AM

Hello, do you know any article related to pagetypebuilder functionality equivalent in epi7?


Bharat  Tyagi
Bharat Tyagi Oct 17, 2014 08:29 AM

Hi Alexandar,

I am new to EPI, and to be very frank don't know the abc of EPI, could you please guide me to some learning source, where some step by step learning course is available.

Please login to comment.
Latest blogs
Enhancing online shopping through Optimizely's personalized product recommendations

In this blog, I have summarized my experience of using and learning product recommendation feature of Optimizely Personalization Artificial...

Hetaxi | Jun 18, 2024

New Series: Building a .NET Core headless site on Optimizely Graph and SaaS CMS

Welcome to this new multi-post series where you can follow along as I indulge in yet another crazy experiment: Can we make our beloved Alloy site r...

Allan Thraen | Jun 14, 2024 | Syndicated blog

Inspect In Index is finally back

EPiCode.InspectInIndex was released 9 years ago . The Search and Navigation addon is now finally upgraded to support Optimizely CMS 12....

Haakon Peder Haugsten | Jun 14, 2024

Change the IP HTTP Header used for geo-lookup in Application Insights


Johan Kronberg | Jun 10, 2024 | Syndicated blog

Copying property values

In this article I’d like to show simple Edit Mode extension for copying property values to other language versions. In one of my previous blogposts...

Grzegorz Wiecheć | Jun 8, 2024 | Syndicated blog

Auto-translate with OpenAI GPT-4o in Optimizely CMS

Improvements for Episerver.Labs.LanguageManager! It's now possible to auto-translate both a page and its children at the same time! Additionally, m...

Tomas Hensrud Gulla | Jun 7, 2024 | Syndicated blog