Created
October 27, 2017 09:51
-
-
Save ps-team/0cf0948ad94612cf4f92a61fb26aa5c4 to your computer and use it in GitHub Desktop.
Group items and wrap in a div in Razor using Skip and Take
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Contensis.Framework.Web | |
@using Contensis.Framework.Web.Search; | |
@{ | |
var relatedContent = CurrentNode.RelatedNodes(); | |
} | |
@if (relatedContent.Count >= 1){ | |
for (var i = 0; i < relatedContent.Count; i += 3) | |
{ | |
<div class="blockWrapper blockWrapperSpaced"> | |
@foreach (var relatedNode in relatedContent.Skip(i).Take(3)) | |
{ | |
var pageType = relatedNode.Type; | |
var publishedDate = relatedNode.Data.DatePublished.ToString("d MMMM yyyy"); | |
var description = relatedNode.Data.Description.ToString(); | |
var charCount = description.Length; | |
var ellipsis = ""; | |
var desc2 = description; | |
if(charCount >= 150) { | |
ellipsis = "…"; | |
desc2 = description.Substring(0, 150) + ellipsis; | |
} | |
<div class="block picBlock picBlockPro"> | |
<div class="block-imgWrap"> | |
@if (relatedNode.ThumbnailUrl != "") | |
{ | |
<a href="@relatedNode.Path"><img src="@relatedNode.ThumbnailUrl" class="block-img" alt="@relatedNode.Title" /></a> | |
}else { | |
<a href="@relatedNode.Path" title="@relatedNode.Title" class="brick-noImgLink brick-noImgLink-@pageType"></a> | |
} | |
</div> | |
<div class="block-content"> | |
<span class="block-meta">@pageType • @publishedDate</span> | |
<h3 class="block-title"><a href="@relatedNode.Path">@relatedNode.Title</a></h3> | |
<p>@Html.Raw(desc2)</p> | |
</div> | |
</div> | |
} | |
</div> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment