Episerver provides us developers with loads of useful and extendable APIs. In today's post, I'm going to quickly go over the IContentTypeRepository and how to write some code that will return all of the page types defined in your website.
var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var pageTypeList = contentTypeRepository.List().OfType<PageType>();
var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentType = contentTypeRepository.Load<ProductPage>();
var usages = contentModelUsage.ListContentOfContentType(contentType).OrderBy(x => x.Name);
Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge