Loading...
Area: Optimizely CMS
ARCHIVED This content is retired and no longer maintained. See the latest version here.

Recommended reading 

Table of Contents

ContentType

The required attribute for block and page types is called ContentType, and is located in the EPiServer.DataAnnotations namespace. The configurable properties for the attribute are displayed below.

Property NameDescriptionDefault value
AvailableInEditMode Defines if you should be able to create content of this type in edit mode. true
Description A short text that describes the function of the ContentType. NULL
DisplayName The name shown in edit mode for content of this type. NULL
Order The sort order used to determine the ContentType’s position in listings. 100
GUID Identifier for the content type. Can be used to match the code definition to an existing definition in the database. Guid.Empty
GroupName Name for grouping content types when displaying them for selection in edit mode. NULL

Access

The access attribute defines which users, roles, and visitor groups that will have access rights to create a page or block based on the content type.

Attribute NameDescriptionBehavior if not specified
Access(
Users=...,
Roles=...,
VisitorGroups=...)
Defines which users, roles, and visitor groups that will have access rights. The role Everyone will be given Create access rights to the type.

The following image shows how the attribute properties are mapped to settings in admin mode.

Included

AvailablePageTypes

There is an additional optional attribute for page types called AvailablePageTypes that can be used to set which page types that should be available under a page instance. The configurable properties for the attribute are displayed below.

Property NameDescriptionDefault value
Availability Defines if all or none page types should be available. If none is set other settings on the attribute is ignored. Availability.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]

The types given on Include, Exclude, IncludeOn and ExcludeOn can either be a typed page (that is a type inheriting PageData) directly or it can be the type of an interface or a baseclass. At registration all registered types that can be assigned to the specified type will be included. For example, if an interface is specified in Include list then all typed pages that implement the interface will be included.

IncludeOn differs from Include in the way that it is not excluding. That is for types in IncludeOn 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. Below is an image that shows how Include and IncludeOn are mapped to settings in admin mode.


Exclude works so that if no types are set on Include then the result will be that all registered page types except the Exclude ones are available. If there are types registered in Include then all types in Include except the ones in Exclude are available. Below is an image that shows how Exclude and ExcludeOn are mapped to settings in admin mode.


Below is an image that shows how Availability is mapped to settings in admin mode.

Availability

TemplateDescriptor

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. The attribute, which exists in the EPiServer.Framework.DataAnnotations namespace, contains the following properties:

Property NameDescriptionDefault value
Path The path to the template to be rendered. Needs to be set if folder structure does not follow namespace structure. There is a namespace convention where the file will be searched for in the path according to the namespace. For example if there is a template with type CodeSamples.Templates.Pages.MyTemplate, then the Path will be resolved if it is located in a folder structure that follows the namespace. So if there is a folder Templates in the application root and it has a sub folder Pages where the file MyTemplate.aspx is located then the Path will be found and hence Path does not need to be set. The system tries to find the template file using the same conventions in the corresponding Shell module folder if the Path property is not set and the template type is associated with a module. The system also tries to resolve the full virtual path to the template file in a module folder when the template type is associated with a Shell module and the Path property value contains a path which is not application relative and not an absolute virtual path. 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 Default defines the template as the default template for the page data type. false
Description Description contains a 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

Property attributes

For properties of content types we use different attributes to describe how they should behave. The following are located in the EPiServer.DataAnnotations namespace.

Attribute NameDescriptionBehavior if not specified
BackingType(Type) Defines the PropertyData type used to store values for this property. Must be a type inheriting from PropertyData. The backing type will be auto determined. See Default Backing Types.
CultureSpecific(bool) Defines if this property should have a different value for each language. Properties will not be culture specific.
Searchable(bool) Defines if the property value should be searchable. String properties will be searchable, all other property types will not.
Ignore Defines if the property should be ignored. By default all properties are included in a content type, you can use this attribute to tell the system to ignore this property.

The following are located in the System.ComponentModel.DataAnnotations namespace.

Attribute NameDescriptionBehavior if not specified
Required Defines if a value for this property must be set before being able to save a page of the parent type. Property value is not required.
ScaffoldColumnAttribute(bool) Defines if this property is visible in Edit mode. Property is visible in edit mode.
Display(
Name=...,
Description=...,
GroupName=...,
Order=...)
The Name, Description, GroupName and Order properties are used to set the EditCaption, HelpText , Tab and FieldOrder respectively. EditCaption is set to the name of the property. HelpText is NULL. Tab is set to the Tab with the lowest sort order.
UIHint Used to select either editor/renderer or both by defining a hint string. You can use EPiServer.Web.UIHint to use hints for known types in the system, for instance UIHint.Image. The default editor and renderer for the type will be used.
StringLength Sets a maximum length for strings. Note that this attribute cannot be used for properties of type XhtmlString. No length restriction.
RegularExpression Validates the input format. Usually used for string properties. No validation of the input.
Range Determines the valid range for numeric properties. No validation of range except the minimum/maximum values for the value type (For instance Int32.MinValue and Int32.MaxValue).

ImageUrl

The attribute called ImageUrl can be used to set the icon for both blocks and pages.

Property NameDescriptionDefault value
Path The path to the icon to use for the page type. NULL

Default Backing Types

If the BackingType attribute has not been set for a property, the backing type will be automatically assigned to a PropertyDefinitionType where the corresponding EPiServer.Core.PropertyData.PropertyValueType matches the property type. That means that if there is a PropertyData implementation (can be a custom property) with matching PropertyValueType that defintion will be used. Otherwise the backing type is assigned according to this table.

BackingTypeProperty Type
PropertyContentArea ContentArea
PropertyBoolean Boolean
PropertyCategory CategoryList
PropertyDate DateTime
PropertyFloatNumber Decimal
Double
Float
Single
PropertyLinkCollection LinkItemCollection
PropertyNumber Byte
Int16
Int32
Int64
PropertyPageType PageType
PropertyLongString String
PropertyTimeSpan TimeSpan
PropertyUrl Url
PropertyXForm XForm
PropertyXhtmlString XhtmlString

The following images show how the attributes are mapped to settings in Admin mode.

AttributeMapping
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EPiServer.Core;
using EPiServer.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using EPiServer.Security;
using EPiServer;
using EPiServer.Web;
using EPiServer.Shell.ObjectEditing.EditorDescriptors;
using EPiServer.Shell.ObjectEditing;

namespace CodeSamples
{
    [ContentType(
        DisplayName="My Page Type",
        Description="Description for this page type",
        Order=1024,
        GUID="9CBBF910-CB5A-4C72-83AA-EDCF02E8A2BD",
        GroupName="My Group",
        AvailableInEditMode=true)]
    [AvailablePageTypes(Include = new Type[] { typeof(MyPageType2), typeof(MyPageType3) })]
    [Access(Users = "niis", Roles = "CmsEditors")]
    public class TypedPageWithAttributeSample : PageData
    {
        [Required]
        [Searchable]
        [CultureSpecific]
        [Editable(true)]
        [Display(
            Name = "My Heading",
            Description = "Heading for my page type.",
            GroupName = "My Tab",
            Order = 64)]
        public virtual string Heading { get; set; }

        //An integer between 0 and 130.
        [Range(0, 130)]
        public virtual int Age { get; set; }

        //A string containing a valid email address.
        [RegularExpression(EPiServer.Framework.Validator.DefaultEmailRegexString)]
        public virtual string Email { get; set; }

        //A string with a maximum length of 20 characters.
        [StringLength(20)]
        public virtual string Header { get; set; }

        //Any URL
        public virtual Url RedirectPage { get; set; }

        //URL to image.
        [UIHint(UIHint.Image)]
        public virtual Url Logotype { get; set; }

        //Creates a selection of predefined values.
        [UIHint("languageselection")]
        public virtual string Language { get; set; }
    }

    [EditorDescriptorRegistration(UIHint = "languageselection")]
    public class CustomLanguageEditorDescriptor : EditorDescriptor
    {
        public CustomLanguageEditorDescriptor()
        {
            //Define an episerver selection editor that can be bound to the values generated
            //from a class implementing ISelectionFactory.
            ClientEditingClass = "epi.cms.contentediting.editors.SelectionEditor";
            SelectionFactoryType = typeof(CustomLanguageSelectionFactory);
        }
    }

    public class CustomLanguageSelectionFactory : ISelectionFactory
    {
        public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
        {
            var languages = new List<SelectItem>();

            languages.Add(new SelectItem() { Text = "English", Value = "en"});
            languages.Add(new SelectItem() { Text = "Swedish", Value = "sv" });
            languages.Add(new SelectItem() { Text = "Norwegian", Value = "no" });

            return languages;
        }
    }

    [AvailablePageTypes(IncludeOn = new Type[] { typeof(TypedPageWithAttributeSample) })]
    [ContentType]
    public class MyPageType1 : PageData { }

    [AvailablePageTypes(Exclude = new Type[] { typeof(TypedPageWithAttributeSample) })]
    [ContentType]
    public class MyPageType2 : PageData { }

    [AvailablePageTypes(ExcludeOn = new Type[] { typeof(MyPageType1) })]
    [ContentType]
    public class MyPageType3 : PageData { }

    [AvailablePageTypes(Availability = EPiServer.DataAbstraction.PageTypeAvailability.Availability.None)]
    [ContentType]
    public class MyPageType4 : PageData { }
}
Do you find this information helpful? Please log in to provide feedback.

Last updated: Mar 25, 2013

Recommended reading