Copied to clipboard

Flag this post as spam?

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


  • David Hammer 41 posts 67 karma points
    Nov 06, 2013 @ 12:35
    David Hammer
    0

    Getting equal node during foreach

    Hi guys.

    I'm running a foreach loop, where I get all the nodes in a current level. In that foreach, I wan't to check wheather or not a node equals another node.

    Here is the code:

    var magazineLevel =  Model.AncestorOrSelf(1).DescendantsOrSelf("Magazine").OrderBy("magazineDate desc, magazineDate");
    var latestMagazine = magazineLevel.Take(1);
    
    foreach (var page in magazineLevel)
    {
        if (page.IsEqual(latestMagazine))
        {
            //do something...
        }else {
            //do things to all the pages in magazineLevel...
        }
    }
    

    I know that "latestMagazine" is the latest node, but I'm having trouble comparing the page node to the latest magazine node. I don't get any errors in the debugger, and the script runs, but nothing happens during that statement.

    Now, my question is as follows:

    What is the correct way to compare and manipulate a node like this in umbraco, razor?

    I hop you guys can help me, as you've done before. / Kind Regards.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Nov 06, 2013 @ 12:55
    Kevin Jump
    0

    I don't know if its the most effiecent. but i usally just compare Url's

    page.Url == latestMagazine.Url

    or you could just compare Ids ? page.Id == latestMagazine.Id ?

  • David Hammer 41 posts 67 karma points
    Nov 06, 2013 @ 13:02
    David Hammer
    0

    Thank you for the reply Kevin. I think I might have had my head up my ass the last hour xD Of course it works :-). Thank you!

Please Sign in or register to post replies

Write your reply to:

Draft