In this tutorial, you will learn about the differences between an Episerver page and an Episerver block. The first concept you need to learn when working with Episerver CMS are pages and blocks. If you have worked with any type of CMS before, pages are pretty self-explanatory. A website will be built out of several different types of page layout. A standard website might have a homepage template, a landing page template, a contact us template and a content page template. Each of these different template types is known in the Episerver world as a page type.

In Episerver, content modelling is done using a code first approach. You will create a new page type in the CMS by creating a class and implementing some special attributes and inheriting from an Episerver base class. To add properties to the template, you add a set of custom properties within that class.

When a content editor creates a page in the Episerver editor, the editor assigns values to the properties that you have defined in the page’s page type/class. That data is then automatically persisted to the database when the page is saved.

Blocks

Blocks can be thought of as components. Blocks should be familiar to anyone who has ever used MVC or web forms. A block can be compared to a partial view within MVC, or, user control in web forms. It's a way of being able to reuse a component throughout your website without having to duplicate your code. Some common examples of normal CMS blocks include carousels, accordions, CTAs, text, banners or even a form.

When you work with blocks within Episerver there are two flavours, shared blocks and local blocks.

Shared Blocks: A shared block is a block that can be re-used throughout your website and are normally created by a content editor. You can see shared blocks in the editor on the right-hand side panel within the blocks tree navigation pane. Shared blocks are normally created within a ContentArea

Local Blocks: A local block is a block that is hard coded onto a page or another block. A local block cannot be reused in other pages and it will not appear in the block tree. Local blocks are normally defined by developers in code.

In terms of code, creating a local block and a shared block is exactly the same. The difference between local and shared is how you define the block in your page or block.

In Episerver, to create an area on your page (or block) that will allow content editors to dynamically add content, you would define a property called a ContentArea. I will cover ContentAreas in a later post, however, in essence, a ContentArea is an area where a collection of blocks can be added. We can use that collection in our HTML to render the blocks. The code to do this is shown below:

Any blocks that the content editor adds/creates in a content area will be created as a shared block.  A local block is a block that you define specifically in the page and block definitions. The code to do this is also shown below:

As the block definition is not dynamic, e.g. its not a ContentArea, it isn't possible to move 'MyBlock' anywhere else outside of MyPage. This makes it a local block and it will not appear in the block tree.


This is all you need to know in order to master content modelling in Episerver CMS. Happy Coding 🤘