Template view
What is it ?
A template view is a view which hosts the modules, it can be selected in the page configuration.
Make a template view
A template view is a Razor view, it is possible to define where the modules can be appear in the view. The template view uses a model to store modules and send them in the component invokeasync method. A module has to be passed in the data property.
An example of a template view could be :
DefaultTemplate.cshtml
@await Component.InvokeAsync(Model.Header.ModuleViewComponent, new { data = Model.Header })
@await Component.InvokeAsync(Model.Body.ModuleViewComponent, new { data = Model.Body })
@await Component.InvokeAsync(Model.Footer.ModuleViewComponent, new { data = Model.Footer })
DefaultTemplateViewModel.cs
using Kastra.Core.ViewComponents;
namespace Kastra.Web.Models.Template
{
public class DefaultTemplateViewModel
{
public ModuleDataComponent Body { get; set; }
public ModuleDataComponent Header { get; set; }
public ModuleDataComponent Footer { get; set; }
}
}
Use a template view
To select the template in the page configurations, the template has to be added in the template table and the module emplacements have to be created. This Kastra_Page_Templates table contains the template name, the namespace, the template keyname which is used to find the view in the template controller view folder. The module emplacements are present in the Places table, it contains the keyname used in the Razor view and the template ID.