8 What renders a page
Two things can say what renders a page: code, once per page type, or a template that an editor chooses for the page. A site can use either or both. Code is the simplest: one line per type, and nothing in the database. Templates are for pages where editors choose between layouts.
For each request, the first of these that gives an answer renders the page:
- A selector. Selectors see every request, in the order you add them (below).
- The page's own template, when the editor chose one. It must be made for the page's type.
- The closest template or code default for the page's type, with two rules for ties (below).
- The view named after the type, when
ViewPerType()is on. - Nothing. The page is not rendered, and the request goes on to
MapFallbackor a 404.
- Code decides: code defaults — A code default says what renders every page of a type that has no template:
- Editors decide: templates — Templates need no code. A template renders by its kind: a view template renders its view, a controller template its action, and a Razor Page template its page (chapter 5). A kind of your own renders as you say (below). A…
- Both together — A page without a template of its own gets the closest template or code default. Two rules settle ties: A template wins over a code default that is just as close. Editors can take over a type by making a template for it…
- Deciding per request: selectors — A selector looks at the request before anything else, for every page. The first selector that returns a target wins. Return null to pass the page on:
- A template kind of your own — A site adds a kind of template by deriving from ITemplate and saying what renders it. Register the interface with the site's other content types, and editors create templates of the new kind like the built-in ones:
- Mistakes are caught early — A wrong setup shows up before a visitor sees it: when an editor saves a page, and in the log when the site starts or a template changes.
- The targets — Every decision above ends in a target, which names the code that renders the page: