In this tutorial, you will get access to a handy cheat sheet that you can refer to whenever you are creating a new property in code using Episerver CMS. Sometimes when you create a property it is often hard to remember all the different options available to you. When content modelling, you will need to know about all the attributes and the backing types available to you in order to set your content editors up for success. If you want another handy Episerver cheatsheet you can read my Episerver Page Type Cheat Sheet.
Attributes
One of the first things that you need to understand about Episerver content modelling are properties. In order to define code-first properties, you need to decorate your properties with attributes. In Episerver, you have lots of attributes to pick from. These range from registration, configuration, validation, and multi-language:
BackingType: Defines which PropertyData
type Episerver should use in the editor. You can create your own custom properties, however, they must inherit from PropertyData
:
CultureSpecific: The CultureSpecific
attribute is useful for multi-language websites. When set, a content editor will be able to enter different text for different languages. When this attribute is not added, the property will default to the main language set within the CMS.
Display: The display attribute is the attribute that registers the property within the CMS. Display
also has these properties you can add:
Name
: The name the content editor will see in the editorDescription
: The tooltip that gets displayed in the new screen dialogGroupName
: The tab the property gets displayed within the CMSOrder
: The position the property is displayed within the editor
Ignore: When applied to a property, this will hide the property within the CMS. This is useful if you're creating backend settings or admins.
Range[x,x]: Validation attribute. If this is set on an int, limits the range of numbers that can be added to the property.
RegularExpression: Validation attribute. When set, the value of the property will need to meet the regex expressions, otherwise, the editor will prevent the containing page from being saved.
Required: Validation attribute. Has to have a value before the page can be saved.
ScaffoldColumnAttribute: This is another visibility attribute. When applied this can will toggle the visibility in edit mode.
Searchable: This property can be used to set if the item should be searchable in Find.
StringLength: Used for validation. If set on a string, determines the max length of the characters a user can enter.
UIHint: UI hints are used to make the MVC helper methods use a specific display template when rendering properties.
Backing-Type Resolver
Asides from attributes, you can also define the type of property you want to model. The property type will define which editor rendering will be displayed within the editor. As you would expect from a CMS, you have access to all the normal things like int
and strings
. The types you choose will determine the type of content a content editor can enter. For example, a PropertyInt
, will restrict editors to being only allowed to add numbers. You also have a number of Episerver specific properties. In this section, you see all of the properties and how they map to a BackingTypeResolver
:
Type | Backing Type |
---|---|
Byte | PropertyNumber |
ContentArea | PropertyContentArea |
CategoryList | PropertyCategory |
ContentReference | PropertyContentReference |
DateTime | PropertyDate |
Decimal | PropertyFloatNumber |
Double | PropertyFloatNumber |
Float | PropertyFloatNumber |
Int | PropertyNumber |
LinkItemCollection | PropertyLinkCollection |
PageReference | PropertyPageReference |
PageType | PropertyPageType |
Single | PropertyFloatNumber |
String | PropertyLongString |
TimeSpan | PropertyTimeSpan |
Url | PropertyUrl |
XForm | PropertyXForm |
XhtmlString | PropertyXhtmlString |
Happy Coding 🤘