In this tutorial, you will learn how Episerver uses generics to deal with all types of content. With the ever-growing needs of content editors to be able to manipulate different things within the editor, from Episerver 7 the notion of supporting multiple content types was introduced. If you want to learn how this was achieved, read on 🔥🔥🔥

The notion of blocks is a great example of non page content. Using components inside of pages is handy. Having a single API allows you to access any content is very handy. In order to implement this functionality, Episerver made a fundamental change by introducing the IContent interface. The IContent interface is the basic building block that will allow a page, block, blog comment or whatever type you want to create, work with Episerver. In Episerver this interface is called IContent.

The IContent Explained

IContent can be found in the Episerver.Core namespace and it defines six members that must be implemented in order for the content type to work in Episerver.

Name: In order for a bit of content to exist in Episerver it must have a name. The name property is a string and will be the thing Episerver displays in edit mode.

ContentLink: This is the Episerver way of uniquely identifying the content. Episerver uses an object called ContentReference. More information about this unique code can be found in, Why Does Episerver Need A Content Reference?

ParentLink: This references the content item's parent item in the page tree. In Episerver, the StartPage is a special content type that defines the websites home page. It's the page your website visitors will see when they first reach your website. The navigation tree build up from pages created under the StartPage. In order for a piece of content to exist, Episerver needs to know where it will live in relation to the StartPage or the RootPage.

IsDeleted: The IsDelete member tells Episerver if the page has been 'soft' deleted. Soft deleted means that the page may still exist in the database, however, a content editor may have moved it into the trash bin. If items are moved into the Trash then they will not be displayed on the website.

ContentTypeID: The Content Type Id describes the content type within Episerver. All content will be built from a type. A start page template may have an ID of 1, a landing page template might have an ID of 2 and a blog post template might have an ID of 3. The content type can be used to determine the template type it uses.

ContentGuid: The idea of needing a content Guid can be confusing when we already have a content link that uniquely identifies the content. The ContentLink tells Episerver how to identify the content. The ContentGuid is the thing that uniquely identifies the item within the current Episerver system. One reason why this property is required is to support tasks like content migration. If you are trying to do an EpiSever content migration (import/export) from an old website into a new database, you may very well have another bit of content with the clashing name. I have never needed to use this feature, however, the ContentGuid ensures these items can be differentiated.

You are now a content reference guru. Use your new knowledge wisely. Happy coding 🤘