SaaS CMS has officially launched! Learn more now.

Default For this page in media selector



is there any way that you can make the media selector (UIHint.Image) as default mark For this page instead of For all sites?

Jan 23, 2019 15:47

Hi Angelica,

Pretty sure it's not possible without building a custom property would love to be corrected though!

Jan 24, 2019 18:51

If you'd like the media selector to just show the "For this page" folder rather than including "For all sites" you could create an editor descriptor like the following:

[EditorDescriptorRegistration(TargetType = typeof(ContentReference), UIHint = "forthispage")]
public class ForThisPageEditorDescriptor : ImageReferenceEditorDescriptor
    public override IEnumerable<ContentReference> Roots
            return new ContentReference[0];

Which you could then use in place of the standard image UI hint:

public virtual ContentReference MyImage { get; set; }
Jan 25, 2019 20:13

The "For this page" is appended last in the array of root items in ContextualContentForestStoreModel. From what I can see, there is no easy way to override this. You would have to extract the original script, change the logic and then overwrite default implementation by defining a Dojo component with the same name as the original. This is far from optimal and might break when you upgrade to newer version. You could also create your own content selector by extracting code from the following Episerver components:

  • epi-cms/widget/ContentSelector
  • epi-cms/widget/ContentSelectorDialog
  • epi-cms/widget/ContextualContentForestStoreModel (this is the key component)

If you are not afraid of "hacks", I have a third option for you: Load the default implementation of ContextualContentForestStoreModel and replace one line in that script from an MVC controller. Thrilling right? :)

public class ClientResourcesOverridesController : Controller
    private const string CacheKey = "ContextualContentForestStoreModel.js";

    private readonly IModuleResourceResolver _moduleResourceResolver;
    private readonly ISynchronizedObjectInstanceCache _objectCache;

    public ClientResourcesOverridesController(IModuleResourceResolver moduleResourceResolver, ISynchronizedObjectInstanceCache objectCache)
        _moduleResourceResolver = moduleResourceResolver;
        _objectCache = objectCache;

    // GET: ContextualContentForestStoreModel
    public ActionResult ContextualContentForestStoreModel()
        var fileContent = _objectCache.Get(CacheKey) as string;

        if (fileContent != null)
            return Content(fileContent, "text/javascript");

        var cmsClientPath = _moduleResourceResolver.ResolveClientPath("CMS", null);

        using (var stream = VirtualPathProvider.OpenFile($"{cmsClientPath}ClientResources/epi-cms/widget/ContextualContentForestStoreModel.js.uncompressed.js"))
            using (var streamReader = new StreamReader(stream))
                fileContent = streamReader.ReadToEnd();

                // This is the key. Change from javascript array push to unshift to make
                // sure the contextRootLoad (For this page) is added first instead of last.
                fileContent = fileContent.Replace(

                _objectCache.Insert(CacheKey, fileContent, new CacheEvictionPolicy(TimeSpan.FromMinutes(10), CacheTimeoutType.Absolute));
                return Content(fileContent, "text/javascript");

For this to work, you also have to load the script override in CMS UI. You can do this in module.config like this:

<?xml version="1.0" encoding="utf-8"?>
        <add name="epi-cms.widgets.base" path="~/ClientResourcesOverrides/ContextualContentForestStoreModel" resourceType="Script" />

Note that this hack will put "For this page" on top in all content selectors, and in Media panel as well.

Edited, Jan 30, 2019 10:40

If you're interested in a custom implementation of the content selector UI component (extracted from the default implementation), you can copy sample code from this Gist:

Jan 30, 2019 13:54
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.