Skip to content

ContentReference Types

beginner

ContentReference is the primary identifier for content items in Optimizely CMS. It wraps an integer ID with optional version and provider information.

Optimizely.Cms.Core

PropertyTypeDescription
IDintThe content item ID
WorkIDintThe version number; 0 means published version
ProviderNamestring?Name of the content provider; null for default
MemberTypeDescription
ContentReference.EmptyReferenceContentReferenceRepresents no content; equivalent to null check
ContentReference.StartPageContentReferenceThe configured start page
ContentReference.RootPageContentReferenceThe root of the content tree
ContentReference.WasteBasketContentReferenceThe trash/recycle bin node
ContentReference.GlobalBlockFolderContentReferenceRoot folder for shared blocks
ContentReference.SiteBlockFolderContentReferenceSite-specific block folder
MethodReturnsDescription
CreateWritableClone()ContentReferenceReturns a mutable copy
ToReferenceWithoutVersion()ContentReferenceStrips version info, returns the published reference
CompareToIgnoreWorkID(ContentReference)boolCompares ignoring version number

PageReference inherits from ContentReference. Functionally identical; exists for backward compatibility with page-specific APIs.

CastDirectionNotes
PageReference to ContentReferenceImplicitAlways safe
ContentReference to PageReferenceExplicitCast required

A property type representing an ordered collection of content items dropped into a region.

PropertyTypeDescription
ItemsIList<ContentAreaItem>Ordered list of items in the area
CountintNumber of items
IsEmptybooltrue when the area contains no items
FilteredItemsIEnumerable<ContentAreaItem>Items filtered by current visitor access and publish state
PropertyTypeDescription
ContentLinkContentReferenceReference to the content item
ContentGroupstringDisplay size/group hint (e.g., β€œwide”, β€œnarrow”)
AllowedRolesIList<string>Roles permitted to view this item
Working with ContentReference
csharp
// Check for empty reference
if (ContentReference.IsNullOrEmpty(page.RelatedArticle))
  return;

// Compare ignoring version
bool isSamePage = refA.CompareToIgnoreWorkID(refB);

// Get the published version reference
var publishedRef = contentRef.ToReferenceWithoutVersion();

// Use well-known references
var startPage = _loader.Get<StartPage>(ContentReference.StartPage);
var trashItems = _loader.GetChildren<IContent>(ContentReference.WasteBasket);
Iterating a ContentArea
csharp
// Render items from a ContentArea property
if (!page.MainContent.IsEmpty)
{
  foreach (var item in page.MainContent.FilteredItems)
  {
      var block = _loader.Get<IContent>(item.ContentLink);
      // render block...
  }
}