Relatude Help

3 Content types

Content types build on IItem. Routable content is an IPage.

public interface IItem : IId, IName { }          // from Relatude.DB: Guid Id, and an indexed string Name

public interface IPage : IItem {
    string MetaTitle { get; set; }
    string MetaDescription { get; set; }
    bool ShowInMenu { get; set; }                   // true by default
    bool ShowInTree { get; set; }                   // true by default; false hides it in the CMS interface's tree
    Reference<ITemplate> Template { get; set; }     // the page's template, or none
    RTree.Parent Parent { get; }                    // the page above it in the page tree
    RTree.Children Children { get; }                // the pages below it
}

public class RTree : OneToMany<IPage, IPage> {    // the page tree
    public class Parent : One { }
    public class Children : Many { }
}

A site declares its own content types on top of them:

using Relatude.CMS.Models;
using Relatude.DB.Nodes;

namespace MySite.Models;

public interface IArticle : IPage {
    string Intro { get; set; }
    [HtmlProperty] string Body { get; set; }
}

public interface INewsList : IPage {
    int PageSize { get; set; }
}

Creating, reading and changing them is plain Relatude.DB:

var article = db.Create<IArticle>();     // not stored yet
article.Name = "Hello world";
article.Intro = "The first article.";
db.Insert(article);
db.AddRelation<IPage>(newsListId, p => p.Children, article.Id);   // below the news list in the page tree

var loaded = db.Get<IArticle>(article.Id);
loaded.Intro = "Changed.";
db.Update(loaded);                       // a changed node is stored only by Update

var latest = db.Query<IArticle>().OrderByMetaDescending(m => m.CreatedUtc).Take(10).Execute();
  • Template is a Reference<ITemplate>. Read it with .TryGet(out var template) or .IsSet(), and set it with .Set(id) before you save the page.
  • Relation ends, such as Parent and Children, are objects, not collections. Change them with db.SetRelation, AddRelation, RemoveRelation and ClearRelation, never by assignment.

Every page has its place in one tree, RTree: Parent is the page above it and Children the pages below. The URL manager builds URLs from it when it is listed among the URL parents (chapter 6), and the CMS interface shows it as its content tree (chapter 17). Do not declare another Parent or Children on a page type: the datamodel refuses a property declared twice in a type's hierarchy. For another tree, such as documents in folders, make a relation of your own and give its ends other names.