Rendering

ASP.NET Core

Default to using Page Templates (+ View Components)

If you use Page Templates for a Page Type, and don't have a fallback Razor View for Basic Routingopen in new window, then any Pages of this Page Type defined through the API will need to have their DocumentPageTemplateConfiguration field manually set with a valid value.

Assigning a Page Template to a Page Programmatically

var page = new HomePage();

string config = JsonConvert.SerializeObject(
  new { identifier = "Sandbox.HomePage" },
  new JsonSerializerSettings
  {
      ContractResolver = new CamelCasePropertyNamesContractResolver(),
      Formatting = Formatting.None,
  });

_ = page.SetValue("DocumentPageTemplateConfiguration", config);

Page Types

Use "Route to View" or "Route to Page Template" with Content Tree based routing

Razor

Keep View Injected Dependencies Minimal

Break up Layout Into Smaller View Components

https://dev.to/seangwright/kentico-xperience-design-patterns-good-layout-hygiene-3ob6open in new window

View Components vs Partial Views

  • Leverage View Components over Partial Views
    • Better type checking, intellisense