Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

List all block and which pages they are used on.

Vote:
 

Hi 

I have an admin module that when clicked shows a page that list all page types that has been built. When a page type is click a new page is shown that displays all links to all pages that are built on that page type. 

I would like to make similar admin module for block types. In short I would like to make two things:

A) I would like a page that display all block types that have been built.  

B) When a block type is clicked I would like to show a new page that displays links to all pages that are using that block type.

How do I make it. 

#154805
Aug 30, 2016 12:17
Vote:
 

Block usage details: http://world.episerver.com/forum/developer-forum/Developer-to-developer/Thread-Container/2016/8/how-can-i-get-all-blocks-and-it39s-usages/

In addition, to list all block types, use IContentTypeRepository:

var contentTypeRepo = ServiceLocator.Current.GetInstance<IContentTypeRepository>();

IEnumerable<ContentType> allBlockTypes = contentTypeRepo.List().Where(x => typeof (BlockData).IsAssignableFrom(x.ModelType));
#154806
Aug 30, 2016 12:47
Vote:
 

Hi and thanks for the reply

However the links provided just refers to other links and refers to some interface, no example of how to implement the interfaces are shown anywhere. 

#154854
Aug 31, 2016 14:15
Vote:
 

There already is a default implementation of the interfaces referred to and you can just inject them in your code (typically in the constructor of a Controller or other class) or by using ServiceLocator.

Example of dependency injection:

public class MyController : Controller
{
    private readonly IContentRepository _contentRepo;
    private readonly IContentModelUsage _modelUsage;

    public MyController(IContentRepository contentRepo, IContentModelUsage modelUsage)
    {
        _contentRepo = contentRepo;
        _modelUsage = modelUsage;
    }
}

Example of ServiceLocator in static class:

public static class SomeHelper
{
    public static void DoStuff()
    {
        var contentRepo = ServiceLocator.Current.GetInstance<IContentRepository>();

        var modelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();
    }
}
#154863
Aug 31, 2016 15:50
Vote:
 

Hi,

Is there an equivilent to this for Episerver 6 R2?

Thanks

Jon

#195101
Jul 13, 2018 10:35
* 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.