Relatude Help

12 Reading the content

The page is found once per request and shared with everything that asks for it:

Where How
an action or a page handler a [FromContent] IArticle article parameter, or [FromContent] ContentMatch match for the template and culture too
a view, a layout, middleware: anywhere with an HttpContext Context.GetContent<IArticle>(), or Context.GetContentMatch()
a service inject RelatudeCmsContext and read Content, or Render for the target too

All of them give null when the request has no page. [FromContent] and GetContent<T>() also give null for a page of another type.

A shared layout reads the page for its title, whichever view renders the body:

@* Views/Shared/_Layout.cshtml *@
@using Relatude.CMS.Models
@using Relatude.DB.CMS.Web.Rendering
@{
    var page = Context.GetContent<IPage>();
}
<title>@(page?.MetaTitle ?? "My site")</title>
<meta name="description" content="@page?.MetaDescription">
ContentMatch Holds
Content the page, as IItem
Template its template, chosen by the editor or found by its type; null when it has none
TemplateByType true when the template was found by type rather than chosen by the editor
TypeDefault the target its code default gave, when it has no template
CultureId, CultureCode the culture the URL matched, such as nb-NO; empty for a URL without one

MVC does not validate a page bound with [FromContent], since validation would follow every relation of the page and read every related node.