|Number of votes:||1|
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.
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 first part of a new page type is creating a page type class(.cs) that inherits from PageData
To display your page type you need a template page (.aspx).
You need to link the page type class to the template in the code behind file (.aspx.cs) by referencing the right class (MyPage).
This is the code needed to define a string property on the 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:
You also need to add the block to the page template:
If you want the page type to have an area where the editor can add “shared blocks” you need a ContentArea property:
You also need to add the content area to the page template:
The available ContentType attributes are:
|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|
|Group name||Name for grouping page types||null|
Defines who has access to create pages of this type.
|Defines who has access to create a new page of this type.||Role Everyone|
The attribute ImageUrl can be used to set the icon for a page type.
You can define in code where the new page type can be created using the AvailablePageTypes attribute.
|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|
|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|
|IncludeOn||States that the page with this attribute should be available under the all the typed pages in the type array.||Type|
|ExcludeOn||States that the page with this attribute should be not available under the any of the typed pages in the type array.||Type|
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.
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.
|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|
A lot of this information is from the excellent EPiServer SDK.