Make a helper to centralize functions
Instead of making essentially duplicate code for lists of content, I made one helper and then everything looks standard.
@helper RenderPost (EngineRecord record, bool detail, bool isfeature) {
<!--<div class="card card-block">-->
if(!isfeature){
<hr/>
}
<div class="post-item">
@if(isfeature){
if(!record.IsDBNull("PostType")){
foreach(CategoryFieldItem topic in record.GetCategory("PostType")) {
<span class="card-label">@topic.Label</span>
}
}
}
<h5 class="post-title">
<a href="/post/@record.Href">
@record.GetString("Title")
</a>
</h5>
<p class="text-muted">
@if([email protected]("PubDate")){
<small>posted on @record.GetDateTime("PubDate").ToString("MMMM dd")</small>
}
</p>
@if (record.GetFiles("PrimaryImage").Count==1) {
<p>
<a href="/post/@record.Href"><img src="@record.GetFiles("PrimaryImage")[0].Url?width=652&height=653" class="img-fluid" alt="@record.GetString("Title")" /></a>
</p>
}
@if([email protected]("Summary")){
<p>@BRT.Raw(record.GetString("Summary"))</p>
}
else if([email protected]("Body")){
<p>@BRT.Raw(record.GetString("Body").Summarize(200))</p>
}
@if([email protected]("FeaturedEvent") && @record.GetRecordList("FeaturedEvent").Count > 0){
foreach(EngineRecord relatedEvent in record.GetRecordList("FeaturedEvent"))
{
<a class="btn btn-secondary btn-sm" href="/event/@relatedEvent.Href"><i class="fa fa-calendar" aria-hidden="true"></i>
@relatedEvent.GetDateTime("StartDate").ToString("MMMM dd")
<span> - View event →</span>
</a>
}
}
@{var photos = record.GetFiles("Photos");}
@if (photos.Count>1) {
int num = 0;
photos.Sort((x,y) => (string.IsNullOrEmpty(x.Title) ? x.Filename : x.Title)
.CompareTo((string.IsNullOrEmpty(y.Title) ? y.Filename : y.Title)));
<div class="card-columns">
@foreach(FileFieldItem file in photos) {
num+=1;
if(num > 9) {
break;
}
if(file.ContentType.StartsWith("image/")) {
<div class="card"><a href="/post/@record.Href"><img src="@file.Url?width=267" class="img-fluid" /></a></div>
}
}
</div>
if(num > 9) {
<p><a href="/post/@record.Href" class="btn btn-secondary btn-sm">View more <i class="fa fa-long-arrow-right" aria-hidden="true"></i></a></p>
}
}
@if (record.GetFiles("Files").Count>=1) {
int num = 0;
foreach(FileFieldItem file in record.GetFiles("Files")) {
if(file.ContentType.StartsWith("audio/")) {
<audio controls>
<source src="@file.Url" type="audio/mpeg">
Your browser does not support the audio tag.
</audio>
}
else if(file.ContentType.StartsWith("video/")) {
<p><a href="/post/@record.Href" class="btn btn-secondary btn-sm"><i class="fa fa-video-camera" aria-hidden="true"></i> Watch</a></p>
}
else {
<p><a href="@file.Url" target="_blank" class="btn btn-secondary btn-sm"><i class="fa fa-paperclip" aria-hidden="true"></i> View file</a></p>
}
if(num > 14) {
break;
}
num+=1;
}
}
@if([email protected]("VideoEmbedCode")){
<div style="max-width:100%;">
@BRT.Raw(record.GetString("VideoEmbedCode"))
</div>
}
@*<div class="clearfix" ></div>
<div class="fb-like" data-href="/post/@record.Href" data-layout="button_count" data-action="like" data-size="small" data-show-faces="false" data-share="true"></div>*@
</div>
}