Creating One Model Multiple Templates in EPiServer

To begin my article on how to create one model for multiple templates, I might start on with describing to you the page template. A template is for generating page outputs of a particular type, sometimes in aspx type of file. The page templates in EPiServer CMS are created using web forms or ASP.NET MVC.

Therefore, a page template is created and used for more than one page type. Usually one to one approach is followed for this process. While creating a page template with MVC and Webforms, a combination of mark ups can be used with server controls, code behind logic and many more.

Creating page templates in Visual Studio

  • Select a folder in the Solution Explorer and save the page template. You can store it in the Web Forms or any other place.
  • Right click on the content menu. Then select to add new items.
  • Next comes the selection of the EPiServer node, page template and entering a name for the new template.
  • Finally click OK.

To use page templates
If a typed page template is used, it gets automatically registered to a supported template for the chosen or specified page type. In order to make the template support extends to all types of pages in the system, EPiServer.Core.PageData. It can also be used as the generic type. Metadata is added to the template as an attribute to the Template Descriptor. This attribute is used to set the template as default for the page data. If a template is strongly typed, the Model Type is easily derived from the generic type. When two pages have one template, then the multi template functionality is used for setting the generic type, it also specifies the Model Type property.

Creating basic template using MVC
You can render an MVC view for a particular page type and create a controller that inherits from EPiServer.Web.Mvc.PageController i.e. M is your page type. This controller is called for page type, when it is chosen as the renderer of the page type. For rendering of the EPiServer CMS properties, the HTML.PropertyFor extension method is used. This particular method calls for another view, that has the same name as property type that the user is about to render.

For example:

public class AcmeStandardPageController : PageController<MyStandardPage>
public ActionResult Index()
return View();

public class MyStandardPage : PageData
public virtual string MyText { get; set; }

Using block templates
For using a block template one must use it to generate output for blocks of given types, mostly as an.ascx of a file or website control. It can be used for more than one block type, yet building up a one to one connection, as a very common and popular approach. The central function of the block template is to access property values so that the blocks can be integrated into the output. To achieve this base classes and User Control are used. It is within the EPiServer CMS API, that has base classes that your web control can inherit from, then again the BlockControllerBase<M> is a very common selection for user controls in implementing IBlockControl<M>. It is considered to be a very common approach for web controls.

Nikunj Bhanushali is associated with Cogzie as Sales & Operations head and who loves sharing information regarding HTML5, CSS3, ASP.Net and JS Angular. Get in touch with him for EpiServer Solution.

About nikunjbhanushali