IContentLoader Interface
Overview
Section titled “Overview”IContentLoader provides read-only access to content. Use instead of IContentRepository when you only need to load content without modifications.
Namespace
Section titled “Namespace”Optimizely.Cms.Core
Methods
Section titled “Methods”| Method | Returns | Description |
|---|---|---|
Get<T>(ContentReference) | T | Loads a single content item by reference |
Get<T>(ContentReference, LoaderOptions) | T | Loads content with custom loader options |
Get<T>(ContentReference, CultureInfo) | T | Loads content in a specific language |
Get<T>(Guid) | T | Loads content by its permanent GUID |
GetChildren<T>(ContentReference) | IEnumerable<T> | Returns immediate children of a node |
GetChildren<T>(ContentReference, CultureInfo) | IEnumerable<T> | Returns children in a specific language |
GetChildren<T>(ContentReference, LoaderOptions, int, int) | IEnumerable<T> | Returns paged children with loader options |
GetAncestors(ContentReference) | IEnumerable<IContent> | Returns all ancestors up to the root |
GetItems(IEnumerable<ContentReference>, CultureInfo) | IEnumerable<IContent> | Batch-loads multiple content items |
LoaderOptions
Section titled “LoaderOptions”| Property | Type | Description |
|---|---|---|
LanguageLoaderOption | CultureInfo | Specifies the language to load |
FallbackLanguageOptions | FallbackOptions | Controls language fallback behavior |
IContentLoader vs IContentRepository
Section titled “IContentLoader vs IContentRepository”| Capability | IContentLoader | IContentRepository |
|---|---|---|
| Get / GetChildren / GetAncestors | Yes | Yes |
| Save / Delete / Move / Copy | No | Yes |
| GetDefault (create new) | No | Yes |
| Recommended for | Templates, views, read paths | Services, scheduled jobs, write paths |
Load typed content
public class ArticleController : Controller
{
private readonly IContentLoader _loader;
public ArticleController(IContentLoader loader)
{
_loader = loader;
}
public IActionResult Index(ContentReference id)
{
var page = _loader.Get<ArticlePage>(id);
return View(page);
}
} Batch-load and list children
// Load multiple items by reference
var refs = new[] { ref1, ref2, ref3 };
var items = _loader.GetItems(refs, CultureInfo.CurrentCulture);
// List children of a specific type
var articles = _loader.GetChildren<ArticlePage>(parentRef)
.Where(a => a.StartPublish <= DateTime.Now)
.OrderByDescending(a => a.StartPublish); Load by GUID
// Useful when the GUID is stored externally
var guid = Guid.Parse("a1b2c3d4-e5f6-7890-abcd-ef1234567890");
var content = _loader.Get<IContent>(guid); Related
Section titled “Related”- IContentRepository Interface — Full read-write content API
- IContent Interface — Base content interface
- ContentReference Types — Reference type details