I got DAMP to work very nicely now. I was just wondering how I can limit the amount of items shown. I've got a downloads item in my sidebar, and only want to show the latest 5 downloads.
Perhaps you should leave the code as it is. In DAMP in the prevalues you can select a max number so if you set that to 5 there will never be more than 5 items. Than you can just sort on the way they are selected. This is not a limitation of DAMP, but of the DynamicXml which is part of Umbraco.
Sorting and only getting the f.e. 5 newest items
Hey,
I got DAMP to work very nicely now. I was just wondering how I can limit the amount of items shown. I've got a downloads item in my sidebar, and only want to show the latest 5 downloads.
I use this to get the links
@inherits umbraco.MacroEngines.DynamicNodeContext
@using DigibizAdvancedMediaPicker
@{
var homeNode = Model.AncestorOrSelf("Home");
var list = @homeNode.Downloads.First();
if (list.HasValue("file")) {
dynamic files = list.file.mediaItem;
if (files.Count() != 0)
{
<h3>@list.Name</h3>
<ul class="downloads">
@foreach (var item in files)
{
var file = item.File;
<li>
<a href="@file.umbracoFile" title="@file.nodeName downloaden">@file.nodeName.@file.umbracoExtension</a>
</li>
}
</ul>
}
}
}
But how can I limit the amount of items shown to 5? And is there a ways to sort them by createDate and not by the order they are in DAMP.
Thx for the help.
I don't think that it's possible with dynamicxml in Razor for v4. Have a look at this topic: http://our.umbraco.org/forum/developers/razor/27730-DAMP-Paging-error-(umbracoMacroEnginesDynamicXml-contains-no-definition-for-Skip). I think it's best to use LinqToXml instead.
Jeroen
Hmz..was happy to finaly got it working like this. I'm quite new to all this.
Can you possibly (help) rewrite my code to use LinqToXml, if it's not allot of trouble?
Sorry I don't have time to rewrite it to LinqToXml. Here are some examples:
http://msdn.microsoft.com/en-us/vstudio/bb688087
http://msdn.microsoft.com/en-us/vstudio/bb738050#take
Perhaps you should leave the code as it is. In DAMP in the prevalues you can select a max number so if you set that to 5 there will never be more than 5 items. Than you can just sort on the way they are selected. This is not a limitation of DAMP, but of the DynamicXml which is part of Umbraco.
Jeroen
Might have found an easier solution, by just using a count.
Will try it and get back to this :)
Thx for your time and help.
Just got it to work like this
@inherits umbraco.MacroEngines.DynamicNodeContext
@using DigibizAdvancedMediaPicker
@{
var position = 1;
var noItems = 5;
var homeNode = Model.AncestorOrSelf("Home");
var list = @homeNode.Downloads.First();
if (list.HasValue("file")) {
dynamic files = list.file.mediaItem;
if (files.Count() != 0)
{
<h3>@list.Name</h3>
<ul class="downloads">
@foreach (var item in files)
{
if(position <= noItems){
var file = item.File;
<li>
<a href="@file.umbracoFile" title="@file.nodeName downloaden">@file.nodeName.@file.umbracoExtension</a>
</li>
position++;
}
}
</ul>
}
}
}
Thx to the CWS movie @ umbraco.tv
And when they want to sort it they'll just have to do it in DAMP, which I think should be very obvious.
Thx again.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.