In this tutorial, you will learn how to get an enumerable list of all the page types defined within your Episerver CMS-powered project. Episerver provides us as developers with loads of useful and extendable APIs that will allow you to do lots of cool things. If you want to learn how to get access to your page-type definitions in code, read on 🔥🔥🔥
IContentTypeRepository
To make this magic work, you will use the IContentTypeRepository
API. The IContentTypeRepository
API will return a list of all of the page-type defined in your website:
Using the List()
method, you can get a list of all the types defined within your website 💥
IContentModelUsage
After you have a list containing all of the types, the next logical step is to query the CMS in order to get a list of all of the pages that have been created using a particular type. You can do this using the IContentModelUsage
API. Using IContentModelUsage
you can pass in the type you care about as T
. In return you will get a list of all the pages and blocks that have been created inside of the CMS with it:
The IContentModelUsage
API is not well known but very handy. Using the ListContentOfContentType()
method you get all related pages from within the CMS 💥
You are now an Episerver content-type guru 🧘🧘🧘. The code in today's tutorial is simple, however, it will allow you to do powerful things. Happy Coding 🤘