📋 Content Models
Built In Properties
📖 Docs

Built-in Properties - Optimizely CMS 12

Exam Area: Content Area 5 – Content Models (25%)
Reference: https://docs.developers.optimizely.com/content-management-system/docs/built-in-properties


1. All Built-in Properties of PageData

// 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
}

2. VersionStatus Enum

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
}

3. ContentReference Properties

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

4. XhtmlString

// 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();

5. ContentArea

// 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)

6. LinkItemCollection

// 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>
    }
}

7. CategoryList

// 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>
}

8. PageShortcutType (LinkType)

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);

9. IContent Interface

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; }
}

10. IVersionable Interface

public interface IVersionable
{
    VersionStatus Status { get; set; }
    DateTime? StartPublish { get; set; }
    DateTime? StopPublish { get; set; }
    bool IsPendingPublish { get; set; }
}

Review Questions

  1. Where does ContentReference.StartPage point? (Start page of the current site)
  2. What does VersionStatus.Published mean? (Content is live/published)
  3. How does XhtmlString differ from string? (XhtmlString supports HTML with TinyMCE; string is plain text)
  4. What is ContentArea used for? (Contains blocks in a drag & drop layout)
  5. What does PageShortcutType.External do? (Redirects to an external URL when the page is accessed)