Blog Post with Topic and Related Content (Detail Page)

A Detail page is a template to be used for a particular type of content. This code creates a Post Detail page that will be used to display each of your Blog Posts. It includes select Related Content (News Articles and Photo Albums), therefore you must make edits to the BlogPosts View to use this code. The instructions are included in the beginning of the code as comments. In order to work with the Blog Posts Lister Page code block, the Friendly URL of this page should be "post".

<!--A Detail page is a template to be used for a particular type of content. -->
<!--This code creates a Post Detail page that will be used to display each of your Blog Posts. -->
<!--It includes select Related Content (News Articles and Photo Albums), therefore you must make edits to the BlogPosts View to use this code. -->
<!--The instructions are below. -->
<!--In order to work with the Blog Posts Lister Page code block, the Friendly URL of this page should be "post".-->


<!--This code block creates a blog post page including author(s) info (if present), related News and related Photo Albums.-->


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


<!--To use this code you MUST make the following edit to the "BlogPosts" View and make sure you have an existing Photo Albums View:-->


<!--In the dashboard main menu, click Admin > Views. You'll see a list of your existing views. -->
<!--If you don't see the "Blog Posts" view, don't worry - it exists, but you can't see it because you haven't made any edits to it yet.-->
<!--Click the green "+New" button on the right side and select "I'd like to customize an existing view". -->
<!--Select "Blog Posts (Content)" from the list.-->


<!--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">-->
<!--  <Relationship Id="RelatedNews" Name="Related News Articles" TableId="Content" ViewId="News" ShowAsTable="true" />-->
<!--  <Relationship Id="RelatedAlbums" Name="Related Photo Albums" TableId="Content" ViewId="PhotoAlbums" ShowAsTable="true" />-->
<!--</FieldSet>-->


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


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


@section head {
    <style>
        .media-metadata {
            margin-bottom: 30px;
        }
        
        .media-metadata .topics > span:not(:last-child):after {
            content: " | ";
        }
    </style>
}


@BRT.Detail(tableId: "Content", viewId: "BlogPosts",
fields: new[] {"PrimaryImage","Title","PubDate",
"Authors.PrimaryImage","Authors.Type","Authors.PreferredName","Authors.FirstName","Authors.MiddleName","Authors.LastName",
"Authors.NameSuffix","Authors.DoNotEmail","Authors.Email","Authors.Description","Authors.Links.Type","Authors.Links.Link",
"RelatedNews.Title","RelatedNews.PrimaryImage","RelatedNews.PubDate","RelatedNews.Summary","RelatedNews.Body","RelatedNews.Topic","RelatedNews.Link",
"RelatedAlbums.Title","RelatedAlbums.PrimaryImage","RelatedAlbums.Summary","RelatedAlbums.Body","RelatedAlbums.PhotoAlbumTopics",
"Summary","Body","Topic","Files"},
template:
@<div>
    <small>
        <div class="media-metadata text-muted">
            @if(!item.IsDBNull("PubDate")) {
              <span>@item.GetDateTime("PubDate").ToShortDateString()</span>
            }
            @if(!item.IsDBNull("PubDate") && !item.IsDBNull("Authors")){
                <span> - </span>
            }
            @if(!item.IsDBNull("Authors")) {
              <span>by: </span>
              <span class="topics">
                  @foreach(EngineRecord item_authors in item.GetRecordList("Authors")) {
                    <span>
                        <a href="/author/@item_authors.Href">
                            @if(!item_authors.IsDBNull("FirstName")) {
                              <span>@item_authors["FirstName"]</span>
                            }
                            @if(!item_authors.IsDBNull("LastName")) {
                              <span>@item_authors["LastName"]</span>
                            }
                        </a>
                    </span>
                    }
              </span>
            }
            @if (!item.IsDBNull("Topic") && item.GetCategory("Topic").Count > 0) {
                <div class="topics">
                    @foreach(CategoryFieldItem topic in item.GetCategory("Topic")) {
                        <span>@topic.Label</span>
                    }
                </div>
            }
        </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>
    }
    @if(!item.IsDBNull("Authors") && item.GetRecordList("Authors").Count > 0) {
            string authorCount = "Authors";
            if(item.GetRecordList("Authors").Count == 1) {
                authorCount = "Author";
            }
            <div class="box box-bg">
                <h4>@authorCount</h4>
                @foreach(EngineRecord item_authors in item.GetRecordList("Authors")) {
                    <div class="media">
                        @if(!item_authors.IsDBNull("PrimaryImage") && item_authors.GetFiles("PrimaryImage").Count > 0) {
                            if(item_authors.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                                <a href="/author/@item_authors.Href">
                                    <img src="@(item_authors.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="img-fluid primaryImg mr-3" alt="@(String.IsNullOrEmpty(item_authors.GetFiles("PrimaryImage")[0].Title) ? item_authors.GetFiles("PrimaryImage")[0].Filename : item_authors.GetFiles("PrimaryImage")[0].Title)"/>
                                </a>
                            }
                        }
                        <div class="media-body">
                            <h5>
                                <a href="/author/@item_authors.Href">
                                    @if(!item_authors.IsDBNull("PreferredName")) {
                                        <span>@item_authors["PreferredName"]</span>
                                    } else {
                                        <span>@item_authors["FirstName"]</span>
                                    }
                                    @if(!item_authors.IsDBNull("MiddleName")) {
                                        <span>@item_authors["MiddleName"]</span>
                                    }
                                    @if(!item_authors.IsDBNull("LastName")) {
                                        <span>@item_authors["LastName"]</span>
                                    }
                                    @if(!item_authors.IsDBNull("NameSuffix")) {
                                        <span>@item_authors["NameSuffix"]</span>
                                    }
                                </a>
                            </h5>
                            @if(!item_authors.IsDBNull("Description")) {
                                <p>@item_authors.GetString("Description").Summarize(250)</p>
                            }
                            <div class="social">
                                @if(!item_authors.IsDBNull("Email")) {
                                    <span><a href="mailto:@item_authors["Email"]" class="email"
                                        data-toggle="tooltip" title="Email"
                                    ></a></span>
                                }
                                @if(!item_authors.IsDBNull("Links") && item_authors.GetRecordList("Links").Count > 0) {
                                    foreach(EngineRecord item_authors_links in item_authors.GetRecordList("Links")) {
                                        if(!item_authors_links.IsDBNull("Type")) {
                                            if(!item_authors_links.IsDBNull("Link")) {
                                                <span><a href="@item_authors_links["Link"]" class="@item_authors_links.GetCategory("Type")[0].Label.ToLower()" target="_blank"
                                                    data-toggle="tooltip" title="@item_authors_links.GetCategory("Type")[0].Label" 
                                                ></a></span>
                                            }
                                        } else {
                                            if(!item_authors_links.IsDBNull("Link")) {
                                                <span><a href="@item_authors_links["Link"]" class="website" target="_blank"
                                                    data-toggle="tooltip" title="Link" 
                                                ></a></span>
                                            }
                                        }
                                    }
                                }
                            </div>
                        </div>
                    </div>
                }
            </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")) {
                bool hasLink = false;
                if(!item_relatednews.IsDBNull("Link")){
                    hasLink = true;
                }
                <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">
                            @if(!hasLink) {
                                <a href="/article/@item_relatednews.Href">
                                    @item_relatednews["Title"]
                                </a>
                            } else {
                                <a href="@item_relatednews["Link"]">
                                    @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")) {
                                foreach(CategoryFieldItem topic in item_relatednews.GetCategory("Topic")) {
                                    <span>@topic.Label</span>
                                }
                            }
                        </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 PHOTO ALBUMS-->
    @if(!item.IsDBNull("RelatedAlbums") && (item.GetRecordList("RelatedAlbums").Count > 0)) {
        <div class="box box-outline">
            <h4>Related Albums</h4>
            @foreach(EngineRecord relatedAlbum in item.GetRecordList("RelatedAlbums")) {
                <article class="media">
                    @if(!relatedAlbum.IsDBNull("PrimaryImage") && relatedAlbum.GetFiles("PrimaryImage").Count > 0) {
                        if(relatedAlbum.GetFiles("PrimaryImage")[0].ContentType.StartsWith("image/")) {
                            <a href="/album/@relatedAlbum.Href">
                                <img src="@(relatedAlbum.GetFiles("PrimaryImage")[0].Url)?width=120&height=120&mode=crop" class="mr-3 img-fluid" alt="@(String.IsNullOrEmpty(relatedAlbum.GetFiles("PrimaryImage")[0].Title) ? relatedAlbum.GetFiles("PrimaryImage")[0].Filename : relatedAlbum.GetFiles("PrimaryImage")[0].Title)"/>
                            </a>
                        }
                    }
                    <div class="media-body">
                        <h5 class="mt-0">
                            <a href="/album/@relatedAlbum.Href">
                                @if(!relatedAlbum.IsDBNull("Title")) {
                                  @relatedAlbum["Title"]
                                }
                            </a>
                        </h5>
                        <small class="media-metadata text-muted">
                            @if (!relatedAlbum.IsDBNull("PhotoAlbumTopics")) {
                                foreach(CategoryFieldItem topic in relatedAlbum.GetCategory("PhotoAlbumTopics")) {
                                    <span>@topic.Label</span>
                                }
                            }
                        </small>
                        @if(!relatedAlbum.IsDBNull("Summary")) {
                            <p>@BRT.Raw(@relatedAlbum.GetString("Summary").Summarize(250))</p>
                        } else {
                            <p>@BRT.Raw(@relatedAlbum.GetString("Body").Summarize(250))</p>
                        }
                    </div>   
                </article>
            }
        </div>
    }
</div>)