Exam Area: Content Area 5 – Content Models (25%)
Reference: https://docs.developers.optimizely.com/content-management-system/docs/properties
| .NET Type | CMS Property Type | Editor |
|---|---|---|
string | LongString/ShortString | Text input |
XhtmlString | XHtmlString | TinyMCE |
int | Number | Number input |
double | FloatNumber | Float input |
bool | Boolean | Checkbox |
DateTime | Date | Date picker |
ContentReference | PageReference | Page selector |
ContentArea | ContentArea | Drag & drop area |
Url | Url | URL input |
IList<string> | StringList | Multi-text |
CategoryList | Category | Category selector |
LinkItemCollection | LinkCollection | Link list |
[Display(
Name = "Heading",
Description = "Help text for editors",
GroupName = SystemTabNames.Content,
Order = 10)]
public virtual string Heading { get; set; }
// Different values per language
[CultureSpecific]
public virtual string LocalizedTitle { get; set; }
// Shared (no attribute = shared)
public virtual int SortOrder { get; set; }
[UIHint(UIHint.Image)]
public virtual ContentReference MainImage { get; set; }
[UIHint(UIHint.Video)]
public virtual ContentReference Video { get; set; }
[UIHint(UIHint.Textarea)]
public virtual string LongDescription { get; set; }
[UIHint("MultiLineText")]
public virtual string Notes { get; set; }
// Hidden from Edit UI
[ScaffoldColumn(false)]
public virtual string InternalData { get; set; }
// 1. Property value class
[PropertyDefinitionTypePlugIn(DisplayName = "Color Picker")]
public class PropertyColor : PropertyString
{
public Color Color
{
get => IsNull ? Color.Empty : Color.FromName(String);
set => String = value.Name;
}
public override IPropertyControl CreatePropertyControl()
{
return new ColorPickerControl();
}
}
// List of a custom type
[ContentType(DisplayName = "Article Page", GUID = "...")]
public class ArticlePage : PageData
{
public virtual IList<LinkItem> RelatedLinks { get; set; }
public virtual IList<string> Tags { get; set; }
public virtual IList<ImageItem> Gallery { get; set; }
}
// Custom item type
public class ImageItem
{
public ContentReference Image { get; set; }
public string Caption { get; set; }
}
// SelectOne - Single select
[SelectOne(SelectionFactoryType = typeof(ColorSelectionFactory))]
[Display(Name = "Text Color")]
public virtual string TextColor { get; set; }
// SelectMany - Multi select
[SelectMany(SelectionFactoryType = typeof(TagSelectionFactory))]
[Display(Name = "Tags")]
public virtual string[] Tags { get; set; }
// Selection factory
public class ColorSelectionFactory : ISelectionFactory
{
public IEnumerable<ISelectItem> GetSelections(ExtendedMetadata metadata)
{
return new[]
{
new SelectItem { Text = "Red", Value = "red" },
new SelectItem { Text = "Blue", Value = "blue" },
new SelectItem { Text = "Green", Value = "green" }
};
}
}
// Override editor for a property type globally
[EditorDescriptorRegistration(
TargetType = typeof(string),
UIHint = "ColorPicker")]
public class ColorPickerEditorDescriptor : EditorDescriptor
{
public override void ModifyMetadata(
ExtendedMetadata metadata,
IEnumerable<Attribute> attributes)
{
ClientEditingClass = "my.colorpicker.Editor";
base.ModifyMetadata(metadata, attributes);
}
}
// Use property settings to configure editor behavior
[ContentType(DisplayName = "My Page", GUID = "...")]
public class MyPage : PageData
{
[BackingType(typeof(PropertyXhtmlString))]
[Settings(typeof(TinyMcePropertySettings))]
public virtual XhtmlString CustomEditor { get; set; }
}
// TinyMCE settings
public class SimpleTinyMceSettings : TinyMcePropertySettings
{
public override string GetConfiguration()
{
return new TinyMceConfiguration()
.AddToolbarRow("bold italic | link")
.Build();
}
}
// Use block as property (inline - stored with page)
[ContentType(DisplayName = "Article Page", GUID = "...")]
public class ArticlePage : PageData
{
[Display(Name = "Hero Section")]
public virtual HeroBlock HeroSection { get; set; }
[Display(Name = "Feature Block")]
public virtual FeatureBlock Feature { get; set; }
}
@* Render inline block *@
@Html.PropertyFor(m => m.CurrentPage.HeroSection)
All content items have:
// ContentData.Property[] - raw property collection
var rawValue = content.Property["Heading"];
// IContent built-in
content.ContentLink // ContentReference
content.ContentGuid // Guid
content.Name // string
content.ParentLink // ContentReference
content.ContentTypeID // int
content.IsDeleted // bool
XhtmlString use? (TinyMCE)[CultureSpecific] attribute do? (Property has different values per language)[UIHint(UIHint.Image)] suggest to the CMS? (Use the image picker editor)SelectOne differ from SelectMany? (Single dropdown vs multi-select)