Resources (Lister Page)

A Lister is a block of code that loads a list of records from a specific view. This code creates a Resources Lister containing Title, Primary Image (if present) and Summary (in the absence of Summary, it loads partial content of the Body). If you add this code to a page, it can be your "Resources" page.

<!--A Lister is a block of code that loads a list of records from a specific view. -->
<!--This code creates a Resources Lister containing Title, Primary Image (if present), -->
<!--and Summary (in the absence of Summary, it loads partial content of the Body). -->
<!--If you add this code to a page, it can be your "Resources" page.-->


@BRT.Lister(tableId: "Content", viewId: "Resources",
fields: new[] {"Title","PubDate","PrimaryImage","Summary","Body","Link"},
template:
@<div>
    @foreach(EngineRecord record in item) {
        string newwindow = null; 
        string link = null;
        if(!record.IsDBNull("Link")){
            link = record.GetString("Link");
            newwindow=" target=\"_blank\" ";
        }  else {
            link = "/resource/" + record.Href;
        }
        <article class="media">
            @if(!record.IsDBNull("PrimaryImage") && record.GetFiles("PrimaryImage").Count > 0) {
                    if(record.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                        <a href="@link" @newwindow>
                            <img src="@(record.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(record.GetFiles("PrimaryImage")[0].Title) ? record.GetFiles("PrimaryImage")[0].Filename : record.GetFiles("PrimaryImage")[0].Title)"/>
                        </a>
                    }
                }
            <div class="media-body">
                <h5 class="mt-0 mb-0">
                    <a href="@link" @newwindow>
                        @record["Title"]
                    </a>
                </h5>
                <small class="media-metadata text-muted">
                    @if(!record.IsDBNull("PubDate")) {
                      <span>@record.GetDateTime("PubDate").ToShortDateString()</span>
                    }
                    @if(!record.IsDBNull("PubDate") && !record.IsDBNull("ResourceTypes")){
                        <span> - </span>
                    }
                    @if (!record.IsDBNull("ResourceTypes") && record.GetCategory("ResourceTypes").Count > 0) {
                        <div class="topics">
                            @foreach(CategoryFieldItem topic in record.GetCategory("ResourceTypes")) {
                                <span>@topic.Label</span>
                            }
                        </div>
                    }
                </small>
                @if(!record.IsDBNull("Summary")) {
                    <p>@BRT.Raw(@record.GetString("Summary").Summarize(250))</p>
                } else {
                    <p>@BRT.Raw(@record.GetString("Body").Summarize(250))</p>
                }
            </div>   
        </article>
    }
</div>)