FAQs with Topics (Lister Page)

<!--A Lister is a block of code that loads a list of records from a specific view. -->
<!--This code creates a FAQs Lister containing Primary Image (if present), Date, Topic(s), -->
<!--and Summary (in the absence of Summary, it loads partial content of the Body). -->
<!--The FAQs View doesn't have Topics, so you'll have to create those under Categories and update the View. -->
<!--The instructions are below. -->
<!--If you add this code to a page, it can be your "FAQs" page.-->

<!--This code block creates a FAQs lister page with Topics.-->
<!--A column on the right side allows your visitors to filter by topic.-->

<!--**IMPORTANT INFORMATION**-->

<!--To use this code you MUST create the "FAQTopics" Category:-->

<!--To create the FAQTopics Category:-->

<!--In the dashboard main menu, click Admin > Categories. Click the green "+New Category Type" button on the right, and name it "FAQ Topics".-->
<!--Click save. You may now create the topics for your FAQs.-->
<!--Save your edits.-->

<div class="row">
    <div class="col-sm-3 order-sm-2">
        @BRT.CategoryList(tableId:"Content", viewId:"FAQs", fieldId:"FAQTopics", 
        template: 
        @<div class="topic-list-wrap">
            <h4 class="topic-list">Topics</h4>
            <p><a href="/faqs">All</a></p>
            @foreach(EngineRecord c in item) {
                <p><a href="/faqs?topic=@c["Id"]">@c["Label"]</a></p>
            }
        </div>)
    </div>
    <div class="col-sm-9">
        @BRT.Lister(tableId: "Content", viewId: "FAQs",
        fields: new[] {"PrimaryImage","Title","PubDate","Summary","Body","FAQTopics"},
        condition: (String.IsNullOrEmpty(Request.QueryString["topic"])?null:ConditionMeta.Parse("[FAQTopics.Id]='" + Request.QueryString["topic"] + "'")),
        template:
        @<div>
          @foreach(EngineRecord record in item) {
            <article class="media">
                @if(!record.IsDBNull("PrimaryImage") && record.GetFiles("PrimaryImage").Count > 0) {
                    if(record.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                        <a href="/faq/@record.Href">
                            <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">
                        <a href="/faq/@record.Href">
                            @if(!record.IsDBNull("Title")) {
                              @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("FAQTopics")){
                            <span> - </span>
                        }
                        @if (!record.IsDBNull("FAQTopics")) {
                            if(record.GetCategory("FAQTopics").Count > 1){
                                foreach(CategoryFieldItem topic in record.GetCategory("FAQTopics")) {
                                    <span class="topic">@topic.Label</span>
                                }
                            } else {
                                foreach(CategoryFieldItem topic in record.GetCategory("FAQTopics")) {
                                    <span>@topic.Label</span>
                                }
                            }
                        }
                    </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>)
    </div>
</div>