Dynamic Razor Pages content in Docify


Pseudo-dynamic content (resolved during the compilation time) can be used when writing layouts and includes. In this case, the files use the Razor Pages syntax and usually named as *.cshtml files, although this is not a requirement.

Razor Pages are resolved using the Razor Light engine.

Such a page can access the data model to read the information about current site, page, metadata etc.

The following snippet will generate the url node and create page's url with title.

<a href="@Model.Page.Data["title"]">@Model.Page.FullUrl</a>

Data model is defined in the Base.Context.dll

Model
    Site - Access to the current site
        Configuration - configuration (dictionary) of the current site
        BaseUrl - base url of the site
        MainPage - root page of the site
    Page - current page
        Url - relative url of the current page
        FullUrl - full url of the current page (including base url)
        Data - Metadata of the current page (dictionary)
        SubPages - Direct children of this page
        Assets - Direct assets of this page
    Data - current metadata of the include

In order to enable IntelliSense, install Xarial.Docify.Base.Context package and specify the model as follows.

Intellisense enabled for the content model in the MS Visual Studio editor
Intellisense enabled for the content model in the MS Visual Studio editor

@page
@using Xarial.Docify.Base.Context
@model IContextModel
<ul>
    @foreach (var childPage in Model.Page.SubPages)
    {    
        <li>@childPage.Url</li>
    }
</ul>

The above code will generate an unordered list of urls of all children pages of the current page.


Powered by Docify