Using Key grouping to show docs based on the date they were published
Hi folks,
I have a strange issue here (strange issues everywhere really, but ony this one matters!)
After much googling and searching the forums I produced the following code last week to show a list of years that a document may have been published for, and then the list of documents for the selected year following it.
Whilst this code seemed to work for a while, it now fails to render the year links properly anymore. I seem to only get the first one, and only if the year is 2012. Even stranger, I have one page with documents underneath it that still works fine. Renders all tabs correctly.
For your reference, this is an example of the output, working fine.
<ul class="tabs">
<li class="selected"><a href="?year=2011">2011</a></li>
<li><a href="?year=2010">2010</a></li>
<li><a href="?year=2009">2009</a></li>
<li><a href="?year=2008">2008</a></li>
<li><a href="?year=2007">2007</a></li>
<li><a href="?year=2002">2002</a></li>
</ul>
<div id="tab-content">
<table id="data">
<tr><td class="date">30 Dec 2011</td><td class="doc"><a target="_blank" href="aDoc.pdf" title="Annual Report for 31 December 2011">Annual Report, 2011 December</a></td><td class="size">827KB</td></tr>
<tr><td class="date">30 Jun 2011</td><td class="doc"><a target="_blank" href="anotherDoc.pdf" title="Interim Financial Report for 30 June 2011">Interim Financial Report, June 2011</a></td><td class="size">576KB</td></tr>
</table>
</div>
It's always a little hard to help with something that used to work but now doesn't - simply because we don't know nearly as much about what has or has not changed between "before" and "after"...
That said, from looking at the code, I can see that if your links don't render, the problem could be that the $data variable only collects nodes that are direct children of $currentPage, thus they're the only ones being iterated (even though the key() may return more "valid" pages).
Unfortunately, the problem is not related to not rendering the doc links, it's the tabs at the top. It is defintely the Key grouping code that seems to be at fault.
Strangely, I have one place where the code is working fine, and another where it only renders one tab, and that is only if it's the current year. It is very strange.
End story for me, I cracked it and rewrote the code as a Razor script in C# after spending 4 hours trying to debug it.
For everyones reference, here is the attached razor code, which of course works.
I'm sure it could be improved, but it works. Feel free to take it and do whatever you wish with it.
@using umbraco.MacroEngines @inherits umbraco.MacroEngines.DynamicNodeContext @{ var pagesToList = @Model.Children.OrderBy("newsDate desc"); var yearParam = HttpContext.Current.Request.QueryString["year"]; var theYear = "0"; var selClass = ""; var xBytes = "";
var yearToDisplay = String.IsNullOrEmpty(yearParam) ? pagesToList.First().GetProperty("newsDate").Value.Substring(0,4) : yearParam;
Using Key grouping to show docs based on the date they were published
Hi folks,
I have a strange issue here (strange issues everywhere really, but ony this one matters!)
After much googling and searching the forums I produced the following code last week to show a list of years that a document may have been published for, and then the list of documents for the selected year following it.
Whilst this code seemed to work for a while, it now fails to render the year links properly anymore. I seem to only get the first one, and only if the year is 2012. Even stranger, I have one page with documents underneath it that still works fine. Renders all tabs correctly.
For your reference, this is an example of the output, working fine.
And this is the code.
Can anyone with a better XSLT head on their shoulder than me see anything potentially wrong with what I have done and point me in the right direction?
Like with everything, this will stop hurting me when I can stop hitting my head against this proverbial brick wall.
Cheers,
Cameron
Was really hoping there would be someone out there who would be able to help...
Please?
Hi Cameron,
It's always a little hard to help with something that used to work but now doesn't - simply because we don't know nearly as much about what has or has not changed between "before" and "after"...
That said, from looking at the code, I can see that if your links don't render, the problem could be that the $data variable only collects nodes that are direct children of $currentPage, thus they're the only ones being iterated (even though the key() may return more "valid" pages).
Could that be part of the problem?
/Chriztian
Hi Chriztian,
thanks for taking the time to reply.
Unfortunately, the problem is not related to not rendering the doc links, it's the tabs at the top. It is defintely the Key grouping code that seems to be at fault.
Strangely, I have one place where the code is working fine, and another where it only renders one tab, and that is only if it's the current year. It is very strange.
End story for me, I cracked it and rewrote the code as a Razor script in C# after spending 4 hours trying to debug it.
For everyones reference, here is the attached razor code, which of course works.
I'm sure it could be improved, but it works. Feel free to take it and do whatever you wish with it.
Cheers,
Cameron
is working on a reply...