Optimizely CMS 12: built-in property types (with code examples)

I’m writing this blog post as a supplement to the official documentation listing built-in Optimizely CMS 12 property types. What I miss in the official documentation is having quick access to snippets for easy copy & paste, and specifically:

  • C# code samples with typical use,
  • Screenshots showing how the property renders in CMS edit mode.

Code examples

Text input

[Required]
[StringLength(150, MinimumLength = 5)]
public virtual string RequiredText { get; set; }Code language: C# (cs)

Textarea

[UIHint(UIHint.Textarea)]
[StringLength(10)]
public virtual string Textarea { get; set; }Code language: C# (cs)

Rich text

public virtual XhtmlString RichText { get; set; }Code language: C# (cs)

Integer (without range constraint)

Integer (without range)
public virtual int Integer { get; set; }Code language: C# (cs)

Integer (with range constraint)

[Range(1, 20)]
public virtual int RangeInt { get; set; }Code language: C# (cs)

Double (without range constraint)

public virtual double Double { get; set; }Code language: C# (cs)

Double (with range constraint)

[Range(0.00, 9999.99)]
public virtual double RangeDouble { get; set; }Code language: C# (cs)

DateTime

public virtual DateTime DateTime { get; set; }Code language: C# (cs)

The newer .NET typed, DateOnly and TimeOnly are not supported by default in CMS 12.

Boolean

public virtual bool Boolean { get; set; }Code language: C# (cs)

Note that if you use Nullable<bool>, it’ll still render the same: as a checkbox with two states, true/false (and not three as in true/false/null)

PageType selector

public virtual PageType PageTypeSelector { get; set; }Code language: C# (cs)

RegularExpressionString

[RegularExpression(@"^[A-Z]\d$")]
public virtual string RegExString { get; set; }Code language: C# (cs)

ImageData

[UIHint(UIHint.Image)]
[AllowedTypes(typeof(ImageData))]
public virtual ContentReference Image { get; set; }Code language: C# (cs)

PageData

[AllowedTypes(typeof(PageData))]
public virtual ContentReference PageReference { get; set; }Code language: C# (cs)

ContentArea

public virtual ContentArea ContentArea { get; set; }Code language: C# (cs)

StringList

public virtual IList<string> StringList { get; set; }Code language: C# (cs)

Enum

Creating an enum dropdown requires a few more lines of code. See my other blog post, Optimizely CMS 12: working with Enums and Content Delivery API, for a code sample 😊

Summary

The list above is not exhaustive, but it covers the typical building blocks of a custom content type. Some of these properties can be further customized using C# attributes for improved validation.

It’s also possible to introduce custom property types, as well as custom front ends for them to display almost anything you want. However, that is another story to share someday.

Enjoy and good luck!

No comments yet, you can leave the first one!

Leave a Comment