Skip to content

IContentLoader Interface

intermediate

IContentLoader provides read-only access to content. Use instead of IContentRepository when you only need to load content without modifications.

Optimizely.Cms.Core

MethodReturnsDescription
Get<T>(ContentReference)TLoads a single content item by reference
Get<T>(ContentReference, LoaderOptions)TLoads content with custom loader options
Get<T>(ContentReference, CultureInfo)TLoads content in a specific language
Get<T>(Guid)TLoads 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
PropertyTypeDescription
LanguageLoaderOptionCultureInfoSpecifies the language to load
FallbackLanguageOptionsFallbackOptionsControls language fallback behavior
CapabilityIContentLoaderIContentRepository
Get / GetChildren / GetAncestorsYesYes
Save / Delete / Move / CopyNoYes
GetDefault (create new)NoYes
Recommended forTemplates, views, read pathsServices, scheduled jobs, write paths
Load typed content
csharp
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
csharp
// 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
csharp
// Useful when the GUID is stored externally
var guid = Guid.Parse("a1b2c3d4-e5f6-7890-abcd-ef1234567890");
var content = _loader.Get<IContent>(guid);