Hi. I have got the name "displayDate" from your own query. Your code lets to guess that it's supposed to be some custom property of your document type. Isn't that?
The "Year" is just a property of the System.DateTime .NET type, so .GroupBy("DisplayDate.Year") should group the list of nodes by the year part of "DisplayDate".
Display descendants nodes with a list
Hi to all,
i'm gabriele from italy and i wrote here many times ago! How are you?
I'm starting to re-use umbraco with razor... And i 'd like to ask you some tips...
Now i've a content like this:
News
--Year
----Node
I tried to use this razor scripts http://www.diplo.co.uk/blog/2011/6/17/using-razor-in-umbraco-47.aspx
to list the nodes divided per year i use this query but i havenm't the results
var nodes = Model.Children.Where("Notizie").OrderBy("displayDate desc");
Any suggestions?
Hi. The "GroupBy" method could be helpful:
@{
var yearGroups = Model.Children.GroupBy("DisplayDate.Year");
foreach(var yearGroup in yearGroups) {
<h2>@ yearGroup.Key</h2>
foreach(var node in yearGroup) {
<p>@node.Name</p>
}
}
}
Thanks for your reply... but this query don't returns any result...
in var yearGroups inside groupby what do yuo mean with displayDate.Year this method where brings the date of my years folder..
and when start for each i haven't node displayed... Mmmmhhh razor could drive me crazy! :)
Thanks for your response
Bye
Hi. I have got the name "displayDate" from your own query. Your code lets to guess that it's supposed to be some custom property of your document type. Isn't that?
The "Year" is just a property of the System.DateTime .NET type, so .GroupBy("DisplayDate.Year") should group the list of nodes by the year part of "DisplayDate".
This is my entire script:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
int pageSize; // How many items per page
int page; // The page we are viewing
/* Set up parameters */
if (!int.TryParse(Parameter.PageSize, out pageSize))
{
pageSize = 6;
}
if (!int.TryParse(Request.QueryString["page"], out page))
{
page = 1;
}
/* This is your basic query to select the nodes you want */
var nodes = Model.Descendants.Where("catCount > 2").OrderBy("displayDate desc");
int totalNodes = nodes.Count();
int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
/* Bounds checking */
if (page > totalPages)
{
page = totalPages;
}
else if (page < 1)
{
page = 1;
}
}
<h2>Found @totalNodes results. Showing Page @page of @totalPages</h2>
<ul>
@foreach (var item in nodes.Skip((page - 1) * pageSize).Take(pageSize))
{
<li><a href="@item.Url">@item.TitoloNews</a> (@item.DisplayDate.ToShortDateString())</li>
}
</ul>
<ul class="paging">
@for (int p = 1; p < totalPages + 1; p++)
{
string selected = (p == page) ? "selected" : String.Empty;
<li class="@selected"><a href="?page=@p" title="Go to page @p of results">@p</a></li>
}
</ul>
The content tree is:
Homepage-
Notizie (DT folder)
Year (DT Folder)
Node (DT page)
when i start this script i have 0 results
This is my problem!
Thanks for your patience
gabriele
is working on a reply...