FAQ with Topics and Related Content (Detail Page)

<!--A Detail page is a template to be used for a particular type of content. -->
<!--This code creates an FAQ Detail page that will be used to display your FAQ articles. -->
<!--It includes the Date, Primary Image (if present), article Content (Body) and attached Files. -->
<!--This code also includes Related Content ( FAQs, News, Events, Resources), -->
<!--therefore you must make edits to the FAQs View to use this code. -->
<!--The instructions are below. -->
<!--In order to work with the FAQs Lister Page code block, the Friendly URL of this page should be "faq".-->

<!--This code block loads a FAQ article, including related content (in this order): -->
<!--FAQs, News, Events, Resources.-->

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

<!--To use this code you MUST create the FAQTopics Category and make the following edit to the "FAQs" View.-->

<!--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.-->


<!--To edit the View:-->

<!--In the dashboard main menu, click Admin > Views. You'll see a list of your existing views. -->
<!--If you don't see the "FAQs" view, don't worry - we can create it easily.-->
<!--Click the green "+New" button on the right side and select "I'd like to create a new type of Content". -->
<!--Enter the name "FAQs" (without the quote marks) and click Create.-->

<!--Now that you're inside the View, click the "Document Map" dropdown list, -->
<!--scroll down to find "FieldSet ArticleFields" and click it (do not click the black "x" circle).-->
<!--In the code, you'll see the following new line:-->

<!--<FieldSet Id="ArticleFields"/>-->

<!--Now replace that whole line with the content below:-->

<!--<FieldSet Id="ArticleFields">-->
<!--  <Category Id="FAQTopics" CatType="FAQ Topics" Name="Topics" Multiple="true" Cmd="After:Body" />-->
<!--  <Relationship Id="RelatedFAQs" TableId="Content" ViewId="FAQs" Name="Related FAQs" ShowAsTable="true" Reciprocal="true" FieldId="RelatedFAQs" />-->
<!--  <Relationship Id="RelatedNews" TableId="Content" ViewId="News" Name="Related News" ShowAsTable="true" />-->
<!--  <Relationship Id="RelatedEvents" TableId="Content" ViewId="Events" Name="Related Events" ShowAsTable="true" Reciprocal="true" FieldId="RelatedFAQs" />-->
<!--  <Relationship Id="RelatedResources" TableId="Content" ViewId="Resources" Name="Related Resources" ShowAsTable="true" />-->
<!--</FieldSet>-->

<!--If you've previously made edits to the View and the "ArticleFields" fieldset is already visible, all you need to do is include the <Relationship> and <Category> lines inside the "ArticleFields" fieldset.-->

<!--Save the view and you're done.-->



@BRT.Detail(tableId: "Content", viewId: "FAQs",
fields: new[] {"Title","Body","FAQTopics","PubDate","Files",
"RelatedNews.Title","RelatedNews.PrimaryImage","RelatedNews.PubDate","RelatedNews.Summary","RelatedNews.Body","RelatedNews.Topic","RelatedNews.Link",
"RelatedEvents.Title","RelatedEvents.StartDate","RelatedEvents.PrimaryImage","RelatedEvents.Summary","RelatedEvents.Body","RelatedEvents.Calendar",
"RelatedResources.Title","RelatedResources.PrimaryImage","RelatedResources.Summary","RelatedResources.Body","RelatedResources.ResourceTypes",
"RelatedFAQs.Title","RelatedFAQs.PrimaryImage","RelatedFAQs.Summary","RelatedFAQs.Body","RelatedFAQs.FAQTopics"},
template:
@<div>
    <small class="media-metadata text-muted">
        @if(!item.IsDBNull("PubDate")) {
          <span>@item.GetDateTime("PubDate").ToShortDateString()</span>
        }
        @if(!item.IsDBNull("PubDate") && !item.IsDBNull("FAQTopics")){
            <span> - </span>
        }
        @if (!item.IsDBNull("FAQTopics") && item.GetCategory("FAQTopics").Count > 0) {
            <div class="topics">
                @foreach(CategoryFieldItem topic in item.GetCategory("FAQTopics")) {
                    <span>@topic.Label</span>
                }
            </div>
        }
    </small>
    @if(!item.IsDBNull("PrimaryImage")) {
      foreach(FileFieldItem file in item.GetFiles("PrimaryImage")) {
        if(file.ContentType.StartsWith("image/")) {
            <div class="primaryImg">
                <img src="@(file.Url)?width=1050&height=300" class="img-fluid"/>
            </div>
        }
      }
    }
    @if(!item.IsDBNull("Body")) {
      <div>@BRT.Raw(@item.GetString("Body"))</div>
    }
    @if(!item.IsDBNull("Files") && item.GetFiles("Files").Count > 0) {
        <div class="box box-outline">
            <h4>Files</h4>
            @foreach(FileFieldItem file in item.GetFiles("Files")) {
                if(file.ContentType.StartsWith("image/")) {
                  <img src="@(file.Url)?width=200&height=200"/>
                } else {
                  <p><a href="@file.Url" target="_blank">@(String.IsNullOrEmpty(file.Title) ? file.Filename : file.Title) <i class="fas fa-external-link-square-alt"></i></a></p>
                }
            }
        </div>
    }
    <!--RELATED FAQs-->
    @if(!item.IsDBNull("RelatedFAQs") && (item.GetRecordList("RelatedFAQs").Count > 0)) {
        <div class="box box-outline">
            <h4>Related FAQs</h4>
            @foreach(EngineRecord relatedFAQ in item.GetRecordList("RelatedFAQs")) {
                <article class="media">
                    @if(!relatedFAQ.IsDBNull("PrimaryImage") && relatedFAQ.GetFiles("PrimaryImage").Count > 0) {
                        if(relatedFAQ.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                            <a href="/faq/@relatedFAQ.Href">
                                <img src="@(relatedFAQ.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(relatedFAQ.GetFiles("PrimaryImage")[0].Title) ? relatedFAQ.GetFiles("PrimaryImage")[0].Filename : relatedFAQ.GetFiles("PrimaryImage")[0].Title)"/>
                            </a>
                        }
                    }
                    <div class="media-body">
                        <h5 class="mt-0">
                            <a href="/faq/@relatedFAQ.Href">
                                @if(!relatedFAQ.IsDBNull("Title")) {
                                  @relatedFAQ["Title"]
                                }
                            </a>
                        </h5>
                        @if (!relatedFAQ.IsDBNull("FAQTopics") && relatedFAQ.GetCategory("FAQTopics").Count > 0) {
                            <small class="media-metadata text-muted">
                                <div class="topics">
                                    @foreach(CategoryFieldItem topic in relatedFAQ.GetCategory("FAQTopics")) {
                                        <span>@topic.Label</span>
                                    }
                                </div>
                            </small>
                        }
                        @if(!relatedFAQ.IsDBNull("Summary")) {
                            <p>@BRT.Raw(@relatedFAQ.GetString("Summary").Summarize(250))</p>
                        } else {
                            <p>@BRT.Raw(@relatedFAQ.GetString("Body").Summarize(250))</p>
                        }
                    </div>   
                </article>
            }
        </div>
    }
    <!--RELATED NEWS-->
    @if(!item.IsDBNull("RelatedNews") && (item.GetRecordList("RelatedNews").Count > 0)) {
        <div class="box box-outline">
            <h4>Related News</h4>
            @foreach(EngineRecord item_relatednews in item.GetRecordList("RelatedNews")) {
                <article class="media">
                    @if(!item_relatednews.IsDBNull("PrimaryImage") && item_relatednews.GetFiles("PrimaryImage").Count > 0) {
                        if(item_relatednews.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                            if(!item_relatednews.IsDBNull("Link")) {
                                <a href="@item_relatednews["Link"]" target="_blank">
                                    <img src="@(item_relatednews.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(item_relatednews.GetFiles("PrimaryImage")[0].Title) ? item_relatednews.GetFiles("PrimaryImage")[0].Filename : item_relatednews.GetFiles("PrimaryImage")[0].Title)"/>
                                </a>
                            } else {
                                <a href="/article/@item_relatednews.Href">
                                    <img src="@(item_relatednews.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(item_relatednews.GetFiles("PrimaryImage")[0].Title) ? item_relatednews.GetFiles("PrimaryImage")[0].Filename : item_relatednews.GetFiles("PrimaryImage")[0].Title)"/>
                                </a>
                            }
                        }
                    }
                    <div class="media-body">
                        <h5 class="mt-0">
                            <a href="/article/@item_relatednews.Href">
                                @if(!item_relatednews.IsDBNull("Title")) {
                                  @item_relatednews["Title"]
                                }
                            </a>
                        </h5>
                        <small class="media-metadata text-muted">
                            @if(!item_relatednews.IsDBNull("PubDate")) {
                              <span>@item_relatednews.GetDateTime("PubDate").ToShortDateString()</span>
                            }
                            @if(!item_relatednews.IsDBNull("PubDate") && !item_relatednews.IsDBNull("Topic")){
                                <span> | </span>
                            }
                            @if (!item_relatednews.IsDBNull("Topic") && item_relatednews.GetCategory("Topic").Count > 0) {
                                <div class="topics">
                                    @foreach(CategoryFieldItem topic in item_relatednews.GetCategory("Topic")) {
                                        <span>@topic.Label</span>
                                    }
                                </div>
                            }
                        </small>
                        @if(!item_relatednews.IsDBNull("Summary")) {
                            <p>@BRT.Raw(@item_relatednews.GetString("Summary").Summarize(250))</p>
                        } else {
                            <p>@BRT.Raw(@item_relatednews.GetString("Body").Summarize(250))</p>
                        }
                    </div>   
                </article>
            }
        </div>
    }
    <!--RELATED EVENTS-->
    @if(!item.IsDBNull("RelatedEvents") && (item.GetRecordList("RelatedEvents").Count > 0)) {
        <div class="box box-outline">
            <h4>Related Events</h4>
            @foreach(EngineRecord relatedevent in item.GetRecordList("RelatedEvents")) {
                <div class="media">
                    @if(!relatedevent.IsDBNull("PrimaryImage") && relatedevent.GetFiles("PrimaryImage").Count > 0) {
                        if(relatedevent.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                            <a href="/event/@relatedevent.Href">
                                <img src="@(relatedevent.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(relatedevent.GetFiles("PrimaryImage")[0].Title) ? relatedevent.GetFiles("PrimaryImage")[0].Filename : relatedevent.GetFiles("PrimaryImage")[0].Title)"/>
                            </a>
                        }
                    }
                    <div class="media-body">
                        <h5 class="mt-0">
                            <a href="/event/@relatedevent.Href">
                                @if(!relatedevent.IsDBNull("Title")) {
                                  @relatedevent["Title"]
                                }
                            </a>
                        </h5>
                        <small class="media-metadata text-muted">
                            @if(!relatedevent.IsDBNull("StartDate")) {
                              <span>@relatedevent.GetDateTime("StartDate").ToShortDateString()</span>
                            }
                            @if(!relatedevent.IsDBNull("StartDate") && !relatedevent.IsDBNull("Calendar")){
                                <span> | </span>
                            }
                            @if (!relatedevent.IsDBNull("Calendar") && relatedevent.GetCategory("Calendar").Count > 0) {
                                <div class="topics">
                                    @foreach(CategoryFieldItem topic in relatedevent.GetCategory("Calendar")) {
                                        <span>@topic.Label</span>
                                    }
                                </div>
                            }
                        </small>
                        @if(!relatedevent.IsDBNull("Summary")) {
                            <p>@BRT.Raw(@relatedevent.GetString("Summary").Summarize(250))</p>
                        } else {
                            <p>@BRT.Raw(@relatedevent.GetString("Body").Summarize(250))</p>
                        }
                    </div>   
                </div>
            }
        </div>
    }
    <!--RELATED RESOURCES-->
    @if(!item.IsDBNull("RelatedResources") && (item.GetRecordList("RelatedResources").Count > 0)) {
        <div class="box box-outline">
            <h4>Related Resources</h4>
            @foreach(EngineRecord relatedResource in item.GetRecordList("RelatedResources")) {
                <article class="media">
                    @if(!relatedResource.IsDBNull("PrimaryImage") && relatedResource.GetFiles("PrimaryImage").Count > 0) {
                        if(relatedResource.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                            <a href="/resource/@relatedResource.Href">
                                <img src="@(relatedResource.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(relatedResource.GetFiles("PrimaryImage")[0].Title) ? relatedResource.GetFiles("PrimaryImage")[0].Filename : relatedResource.GetFiles("PrimaryImage")[0].Title)"/>
                            </a>
                        }
                    }
                    <div class="media-body">
                        <h5 class="mt-0">
                            <a href="/resource/@relatedResource.Href">
                                @if(!relatedResource.IsDBNull("Title")) {
                                  @relatedResource["Title"]
                                }
                            </a>
                        </h5>
                        @if (!relatedResource.IsDBNull("ResourceTypes") && relatedResource.GetCategory("ResourceTypes").Count > 0) {
                            <small class="media-metadata text-muted">
                                <div class="topics">
                                    @foreach(CategoryFieldItem topic in relatedResource.GetCategory("ResourceTypes")) {
                                        <span>@topic.Label</span>
                                    }
                                </div>
                            </small>
                        }
                        @if(!relatedResource.IsDBNull("Summary")) {
                            <p>@BRT.Raw(@relatedResource.GetString("Summary").Summarize(250))</p>
                        } else {
                            <p>@BRT.Raw(@relatedResource.GetString("Body").Summarize(250))</p>
                        }
                    </div>   
                </article>
            }
        </div>
    }
</div>)