ContentReference Types
Overview
Section titled βOverviewβContentReference is the primary identifier for content items in Optimizely CMS. It wraps an integer ID with optional version and provider information.
Namespace
Section titled βNamespaceβOptimizely.Cms.Core
ContentReference
Section titled βContentReferenceβProperties
Section titled βPropertiesβ| Property | Type | Description |
|---|---|---|
ID | int | The content item ID |
WorkID | int | The version number; 0 means published version |
ProviderName | string? | Name of the content provider; null for default |
Static members
Section titled βStatic membersβ| Member | Type | Description |
|---|---|---|
ContentReference.EmptyReference | ContentReference | Represents no content; equivalent to null check |
ContentReference.StartPage | ContentReference | The configured start page |
ContentReference.RootPage | ContentReference | The root of the content tree |
ContentReference.WasteBasket | ContentReference | The trash/recycle bin node |
ContentReference.GlobalBlockFolder | ContentReference | Root folder for shared blocks |
ContentReference.SiteBlockFolder | ContentReference | Site-specific block folder |
Methods
Section titled βMethodsβ| Method | Returns | Description |
|---|---|---|
CreateWritableClone() | ContentReference | Returns a mutable copy |
ToReferenceWithoutVersion() | ContentReference | Strips version info, returns the published reference |
CompareToIgnoreWorkID(ContentReference) | bool | Compares ignoring version number |
PageReference
Section titled βPageReferenceβPageReference inherits from ContentReference. Functionally identical; exists for backward compatibility with page-specific APIs.
| Cast | Direction | Notes |
|---|---|---|
PageReference to ContentReference | Implicit | Always safe |
ContentReference to PageReference | Explicit | Cast required |
ContentArea
Section titled βContentAreaβA property type representing an ordered collection of content items dropped into a region.
Properties
Section titled βPropertiesβ| Property | Type | Description |
|---|---|---|
Items | IList<ContentAreaItem> | Ordered list of items in the area |
Count | int | Number of items |
IsEmpty | bool | true when the area contains no items |
FilteredItems | IEnumerable<ContentAreaItem> | Items filtered by current visitor access and publish state |
ContentAreaItem properties
Section titled βContentAreaItem propertiesβ| Property | Type | Description |
|---|---|---|
ContentLink | ContentReference | Reference to the content item |
ContentGroup | string | Display size/group hint (e.g., βwideβ, βnarrowβ) |
AllowedRoles | IList<string> | Roles permitted to view this item |
Working with ContentReference
// 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
// 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...
}
} Related
Section titled βRelatedβ- IContent Interface β ContentLink and ParentLink properties
- Property Types Reference β All CMS property types
- IContentLoader Interface β Loading content by reference