How to find instance of block or page in CMS


The title is self explanatory. As an example, let's say i have a FooBlock and a FooPage. How do I find all instances of the FooBlock and the FooPage in the CMS? Searching for the FooBlock in the assets pane and the FooPage in the navigation pane does not yield any results.

Dec 12, 2017 10:01

If you want that kind of functionality in the editor i think you will have to index the classname to the search index yourself.

Implementation would vary depending on search provider. undecided

Dec 12, 2017 14:37

this should be what you're after

var contentTypeRepository= ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var modelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();

var blockType= contentTypeRepository.Load(typeof(BLOCKTYPE));

var items = modelUsage.ListContentOfContentType(blockType);

then use contentlink property on each of the items to get a reference to all the blocks/pages of that type.

Dec 12, 2017 14:39

I ment through the editor interface. Sorry if I was unclear.

Dec 12, 2017 14:41

I would yeild caution on contentModelUsage as I think this queries the database instead of cache.  My fellow collegues might know the answer about the database quering but I am pretty sure it does.

Dec 12, 2017 14:43

Sorry for the misunderstanding.

I am not sure you can without using episerver find or writing your own module to do so.  EPiServer find has "Power Slice" but you will need to have a find license.

Dec 12, 2017 14:45

you do something as follows

 [Component(PlugInAreas = "/episerver/cms/assets", Categories = "cms", WidgetType = "modeltypesearch/modelsearch", Title = "Content Type Search", Description = "")]
  public class ModelTypeSearchComponent : ContentQueryBase
  public override string Name
            get { return "CustomQuery"; }

        protected override IEnumerable<IContent> GetContent(ContentQueryParameters parameters)
/ /Enter code above based on input to search for type.
    <div class="epi-gadgetInnerToolbar" data-dojo-attach-point="toolbar">
        <div data-dojo-type="dijit.form.TextBox" data-dojo-attach-point="queryText" data-dojo-props="intermediateChanges:true" data-dojo-attach-event="onChange: _reloadQuery"></div>
    <div data-dojo-type="epi.cms.component.ContentQueryGrid" data-dojo-attach-point="contentQuery"></div>

The above is your template for the module.

then in module config, add the following

<?xml version="1.0" encoding="utf-8"?>
    <add assembly="YourAssemblyName" />
    <add name="modeltypesearch" path="ModeTypelSearch" />

Give that a try. 
so   the template and code goes in   

Dec 12, 2017 14:53
* 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.