Exam Area: Content Area 5 – Content Models (25%)
Reference: https://docs.developers.optimizely.com/content-management-system/docs/built-in-properties
// Automatically available on all pages, no declaration needed
public class PageData : ContentData, IContent, IVersionable, IRoutable
{
// Content identity
ContentReference ContentLink { get; set; } // ContentReference
ContentReference ParentLink { get; set; } // Parent page
Guid ContentGuid { get; set; } // Stable GUID
string ContentTypeName { get; } // Type name
// Display
string Name { get; set; } // Page name in tree
string PageName { get; } // Same as Name
// Routing
string ExternalURL { get; set; } // External URL (redirect)
UrlSegment UrlSegment { get; set; } // URL segment
// SEO
string MetaTitle { get; set; } // <title> tag
string MetaKeywords { get; set; } // Meta keywords
string PageDescription { get; set; } // Meta description
bool VisibleInMenu { get; set; } // Show in nav menus
// Structure/Sorting
int SortOrder { get; set; } // Sort within parent
PageShortcutType LinkType { get; set; } // Normal/Shortcut/External
// Versioning (from IVersionable)
DateTime? StartPublish { get; set; } // Publish from date
DateTime? StopPublish { get; set; } // Publish until date
VersionStatus Status { get; } // Published/Draft/etc
// Culture
string LanguageBranch { get; } // Current language
CultureInfo Language { get; } // Language as CultureInfo
CultureInfo MasterLanguage { get; } // Master language
}
public enum VersionStatus
{
NotCreated = 0,
CheckedOut = 10, // Being edited
CheckedIn = 20, // Checked in, awaiting review
DelayedPublish = 40, // Scheduled publish
PreviouslyPublished = 50, // Previously published
Rejected = 60, // Rejected
Published = 100 // Currently published
}
// Check
if (content.Status == VersionStatus.Published)
{
// Content is live
}
ContentReference.RootPage // ID = 1 (root of page tree)
ContentReference.StartPage // Start page of current site
ContentReference.WasteBasket // Recycle bin
ContentReference.GlobalBlockFolder // Global blocks container
ContentReference.SiteBlockFolder // Site-level blocks container
// ContentReference struct
var link = new ContentReference(123); // ID only
var withVersion = new ContentReference(123, 456); // ID + VersionID
link.ID // int - content ID
link.WorkID // int - version ID (0 = published)
link.ProviderName // string - content provider
// Rich text property type
[CultureSpecific]
[Display(Name = "Main body")]
public virtual XhtmlString MainBody { get; set; }
// In View
@Html.PropertyFor(m => m.CurrentPage.MainBody)
// Check null/empty
if (!ContentReference.IsNullOrEmpty(page.MainBody?.ContentLinks?.FirstOrDefault()))
{
// has internal links
}
// Get string content
string htmlString = page.MainBody?.ToString();
// Drag & drop area for blocks
[Display(Name = "Main content area")]
public virtual ContentArea MainContentArea { get; set; }
// Inline blocks
[Display(Name = "Hero area")]
[AllowedTypes(typeof(HeroBlock), typeof(BannerBlock))]
public virtual ContentArea HeroArea { get; set; }
// In View
@Html.PropertyFor(m => m.CurrentPage.MainContentArea)
// List of links
[Display(Name = "Related links")]
public virtual LinkItemCollection RelatedLinks { get; set; }
// In View
@if (Model.CurrentPage.RelatedLinks != null)
{
foreach (var link in Model.CurrentPage.RelatedLinks)
{
<a href="@link.Href" target="@link.Target">@link.Text</a>
}
}
// Multiple categories assignment
[Display(Name = "Categories")]
public virtual CategoryList Categories { get; set; }
// Check category
if (page.Categories != null && page.Categories.Contains(5)) // Category ID 5
{
// Page belongs to category
}
// In View
@foreach (var categoryId in Model.CurrentPage.Categories ?? new CategoryList())
{
var cat = CategoryRepository.Load(categoryId);
<span>@cat.Name</span>
}
public enum PageShortcutType
{
Normal = 0, // Normal page (renders template)
Shortcut = 1, // Shortcut to another page
FetchData = 2, // Fetch content from another page
External = 3, // External URL redirect
Inactive = 4 // Page is not active
}
// Set as shortcut
page.LinkType = PageShortcutType.Shortcut;
page.ShortcutLink = new ContentReference(targetPageId);
public interface IContent
{
ContentReference ContentLink { get; set; }
string Name { get; set; }
ContentReference ParentLink { get; set; }
Guid ContentGuid { get; set; }
int ContentTypeID { get; set; }
bool IsDeleted { get; set; }
PropertyDataCollection Property { get; }
}
public interface IVersionable
{
VersionStatus Status { get; set; }
DateTime? StartPublish { get; set; }
DateTime? StopPublish { get; set; }
bool IsPendingPublish { get; set; }
}
ContentReference.StartPage point? (Start page of the current site)VersionStatus.Published mean? (Content is live/published)XhtmlString differ from string? (XhtmlString supports HTML with TinyMCE; string is plain text)ContentArea used for? (Contains blocks in a drag & drop layout)PageShortcutType.External do? (Redirects to an external URL when the page is accessed)