|Number of votes:||4|
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 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.
Here is a simple page type class that defines our page type MyPage:
MyPage has a single string property called MyName.
We now need a page template that can render pages of our page type MyPage.
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.)
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.