Skip to content

Instantly share code, notes, and snippets.

@zpqrtbnk
Last active December 23, 2015 04:49
Show Gist options
  • Save zpqrtbnk/6582377 to your computer and use it in GitHub Desktop.
Save zpqrtbnk/6582377 to your computer and use it in GitHub Desktop.
Demo usage of ToContentSet()
// IPublishedContent implements IsFirst, IsOdd, Index and various stuff
// so technically it's possible to do
@foreach(var content in contents)
{
<div class="@(content.IsFirst() ? "first" : "") @(content.IsOdd() ? "odd" : "even")" id="item-@(content.Index())">
@content.Name
</div>
}
// however, because of some issues in IPublishedContent, IsFirst, IsOdd, Index... all
// gave random results as soon as contents was not the origin children collection.
// this has been fixed but requires the usage of the .ToContentSet() method:
var contents = Model
.Children()
.Where(x => x.GetPropertyValue<int>("whatever") > 10)
.OrderBy(x => x.Name)
.ToContentSet();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment