Relatude Help

Everything together

A site with a page tree, its home page at /, a code default for every page type and a selector. Its page types are IHomePage : ISite (a site, at the top of its page tree), and ISectionPage, IProductPage (with a bool InStock) and ILandingPage, each an IPage.

using MySite.Models;
using Relatude.CMS.Models;
using Relatude.DB.CMS.Web.Rendering;
using Relatude.DB.Datamodels;
using Relatude.DB.Web;

var homeId = new Guid("6f0c2a9e-3b7d-4e51-8a26-d94c1f0b7e35");   // the home page has a fixed id

var builder = WebApplication.CreateBuilder(args);

builder.AddRelatudeDB(o => {
    o.OnDatamodelInit = (dm, _) => {
        dm.AddCmsContentModel();                     // pages, their tree (RTree) and templates
        dm.AddNamespace<IHomePage>();                // the site's page types
    };
    o.CreateUrlManager = _ => new DefaultUrlManager(new DefaultUrlManagerOptions {
        Parents = [new UrlParentRelation { ParentRelationName = nameof(RTree) }],   // /products/bikes/trail-one
        FallbackRootId = homeId,                                                       // the home page at "/"
    });
    o.OnStoreOpenBackground = db => {                // the home page, on the first start
        if (!db.TryGet<IHomePage>(homeId, out _)) db.CreateAndInsert<IHomePage>(h => h.Name = "Home", homeId);
    };
});

builder.AddRelatudeCMS()
    .AddMvcRendering().AddRazorPagesRendering()
    .AddRendering(o => o
        .Select((http, m) => http.Request.Query["format"] == "json"       // ?format=json: any page as JSON
            ? new ResultTarget((_, c) => Results.Json(new { c.Content.Id, c.Content.Name }))
            : null)
        .RenderRazorView<IHomePage>("Home")
        .RenderMvcController<ISectionPage>("Section")
        .RenderRazorView<IProductPage>(p => p.InStock ? "Product" : "ProductSoldOut")
        .RenderRazorPage<ILandingPage>("Landing")
        .RenderRazorView<IPage>("Default"));        // any other page

var app = builder.Build();

app.UseRelatudeCMS();
app.UseStaticFiles();
app.UseRouting();
app.MapRelatudeCMS();
app.MapFallback(() => Results.NotFound("No page here."));

app.Run();

Once editors have built the tree below the home page:

/                                        the home page, with the view Home
/products                                a section page, with SectionController.Index
/products/bikes/trail-one                a product, with the view Product, or ProductSoldOut
/products/bikes/trail-one?format=json    the selector: the page's id and name as JSON

A template an editor gives a page wins over its code default (chapter 5). Chapter 23 puts every option in one Program.cs.