---
title: Resolve the currently loaded content context
slug: cms-11/dev-docs/resolving-current-content-context
docTags: 
createdAt: 2026-07-22T19:45:20.939Z
---

To resolve the current loaded content context, get an instance of `CurrentContentContext` object. You should run any custom logic in any of the Content Events:

```csharp
[ModuleDependency(typeof (EPiServer.Shell.UI.InitializationModule))]
public class CustomModule: IConfigurableModule {
  public void Initialize(InitializationEngine context) {
    context.Locate.ContentEvents().CreatedContent += CreatedContent;
    context.Locate.ContentEvents().CreatingContent += CreatingContent;
  }

  private void CreatingContent(object sender, ContentEventArgs e) {
    var currentContentContext = ServiceLocator.Current.GetInstance<CurrentContentContext>();
    // we know which content context initiated the CREATE operation        
    var currentContentLink = currentContentContext.ContentLink;

    var newlyCreatedContentLink = e.ContentLink; // --> null as at this point the ContentReference was not assigned yet
  }

  private void CreatedContent(object sender, ContentEventArgs e) {
    var newlyCreatedContentLink = e.ContentLink; // this is the ContentReference of the newly created content item
    // but we might need the ContentReference of the content that was being viewed when the CREATE operation was run
    var currentContentContext = ServiceLocator.Current.GetInstance<CurrentContentContext>();
    // this gives us the content context the editor was in
    var currentContentLink = currentContentContext.ContentLink;
  }

  public void Uninitialize(InitializationEngine context) {
    context.Locate.ContentEvents().CreatedContent -= CreatedContent;
    context.Locate.ContentEvents().CreatingContent -= CreatingContent;
  }

  public void ConfigureContainer(ServiceConfigurationContext context) {

  }
}
```

It also might be useful to know the current content context in any metadata-aware component, such as  an `EditorDescriptor`, for example.

```csharp
public class FooPageType: PageData {
  [EditorDescriptor(EditorDescriptorType = typeof (CollectionEditorDescriptor<OfferDetailsItem>))]
  public virtual IList<OfferDetailsItem> OfferDetailsItems {
    get;
    set;
  }
}

public class OfferDetailsItem {
  [Display(Order = 1)]
  [UIHint("test")]
  public string Label {
    get;
    set;
  }
}

[PropertyDefinitionTypePlugIn]
public class OfferDetailsItemPropertyList: PropertyList<OfferDetailsItem> {}

[EditorDescriptorRegistration(TargetType = typeof (string), UIHint = "test")]
public class CustomXhtmlDescriptor: StringEditorDescriptor {
  private readonly CurrentContentContext _currentContent;

  public CustomXhtmlDescriptor(CurrentContentContext currentContent) {
    _currentContent = currentContent;
  }

  public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes) {
    base.ModifyMetadata(metadata, attributes);

    var ownerContent = metadata.FindOwnerContent(); // --> will return null because the object we annotate is not ContentData but simple POCO
    var currentContent = _currentContent.ContentLink; // --> will return correct page id
  }
}
```

**Related blog posts**

- [TinyMCE customization depending on page context](https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2021/9/tinymce-customization-depending-on-page-context/)
- [Get the value of context=epi.cms.contentdata](https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2020/12/get-value-of-contextepi-cms-contentdata/#234848)
- [Current content for PropertyList item selection factory](https://world.optimizely.com/forum/developer-forum/CMS/Thread-Container/2016/1/current-content-for-propertylist-item-selection-factory/)
