Skip to content

Instantly share code, notes, and snippets.

@phillip-haydon
Created July 9, 2013 17:31
Show Gist options
  • Save phillip-haydon/5959381 to your computer and use it in GitHub Desktop.
Save phillip-haydon/5959381 to your computer and use it in GitHub Desktop.
Sample view for BuildStarted
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<Sandra.Snow.PreCompiler.PostData>
@using System.Collections.Generic
@{
Layout = "default.cshtml";
}
<h1>Archives</h1>
@foreach(var year in Model.PostsGroupedByYearThenMonth)
{
@foreach(var month in year.Value)
{
<h2>@month.Key, @year.Key</h2>
<ul class="archive fancy-container darkishred">
@foreach(var post in month.Value)
{
<li><a href="@post.Url">@post.Title</a></li>
}
</ul>
}
}
var result = new Dictionary<int, Dictionary<int, List<Post>>>
{
{
2013, new Dictionary<int, List<Post>>
{
{
12, new List<Post>
{
new Post
{
Title = "Hello World 2013 - 12",
Url = "My Url"
}
}
},
{
3, new List<Post>
{
new Post
{
Title = "Hello World 2013 - 03",
Url = "My Url"
}
}
},
}
},
{
2012, new Dictionary<int, List<Post>>
{
{
11, new List<Post>
{
new Post
{
Title = "Hello World 2012 - 11",
Url = "My Url"
},
new Post
{
Title = "Hello World 2012 - 11 another one same month",
Url = "My Url"
}
}
},
{
4, new List<Post>
{
new Post
{
Title = "Hello World 2012 - 03",
Url = "My Url"
}
}
},
}
},
};
public class Post
{
public Title { get; set; }
public Url { get; set; }
}
@Buildstarted
Copy link

foreach(PostsGroupedByYearThenMonth) >
    foreach(Value) {
        h2 |@Key, @parent.Key
        ul.archive.fancy-container.darkishred(Value) > li > a[href='@Url'] |@Title
    }

so this is how it should work but i don't currently have a way to get the outer loop so everything there should work except the @parent.Key - i'll figure something out eventually

@phillip-haydon
Copy link
Author

If you can't figure it out, don't worry, I actually updated the keys to be DateTime for another section. So its not an issue now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment