"Dinamico" Razor Content Registration

Defining the Type

The Dinamico page types are located in your site's Themes folder, e.g.

~/Dinamico/Themes/Default/Views/ContentPages/Index.cshtml

 Simply create a .cshtml file in this folder to define a new page type. You'll then need to decorate this file with Dynamic Registrations, explained below. The page type is available in the N2CMS Admin UI as soon as you save the page. You don't need to recompile the web application.

Dynamic page types are only available when using ASP.NET MVC and Razor, and are tested using .NET 4.5 and higher (although they may work with other versions of .NET). Dinamico is not generally compatible with the Web Forms template pack. You need to install the Nuget packages for ASP.NET MVC and Razor in order for Dinamico to work. The Dinamico Nuget package will install these for you.

Creating a View

The basic idea is to be able to create multilpe views with different editors by only adding a view. This is a step aside from a fully strongly typed model.

The idea is to to add cshtml files with Dynamic Registrations, which look like this:

@{
	Content.Define(re => 
	{
		re.Title = "News page";
		re.DefaultValue("Visible", false);
		re.RestrictParents("Container");
		re.Sort(N2.Definitions.SortBy.PublishedDescending);
	});
}

The file executed by this init method...

engine.RegisterViewTemplates<Controllers.ContentPagesController>();

...builds up a template definition connected to the ContentPage type, by executing the Content.Define method demonstrated above. The filename is stored in as TemplateKey and is used to find the correct view to render. The Dynamic Registration Methods (on the re object in the example above) enable you to add various Editors to this dynamic template.

The registrations only applies to items registered as view templates. By default, the _Layout.cshtml file is NOT registered as a view template directly. Therefore, dynamic registrations in that file won't be shown in the N2CMS Admin UI. However, Razor syntax will still work in general.

For ideas of the types of editors you can add using Dynamic Registration, also see the following topics in the N2CMS documentation: