Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michiel 30 posts 61 karma points
    Feb 22, 2012 @ 15:49
    Michiel
    0

    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>
                       <href="@file.umbracoFile" title="@file.nodeName downloaden">@file.nodeName&#46;@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.

  • Jeroen Breuer 4860 posts 12127 karma points MVP 3x admin c-trib
    Feb 22, 2012 @ 15:53
    Jeroen Breuer
    0

    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

  • Michiel 30 posts 61 karma points
    Feb 22, 2012 @ 16:04
    Michiel
    0

    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?

  • Jeroen Breuer 4860 posts 12127 karma points MVP 3x admin c-trib
    Feb 22, 2012 @ 16:20
    Jeroen Breuer
    0

    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

  • Michiel 30 posts 61 karma points
    Feb 22, 2012 @ 16:22
    Michiel
    0

    Might have found an easier solution, by just using a count.

    Will try it and get back to this :)

  • Michiel 30 posts 61 karma points
    Feb 22, 2012 @ 16:28
    Michiel
    1

    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>
                       <href="@file.umbracoFile" title="@file.nodeName downloaden">@file.nodeName&#46;@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.

Please Sign in or register to post replies

Write your reply to:

Draft