Copied to clipboard

Flag this post as spam?

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


  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Mar 02, 2011 @ 17:10
    Douglas Robar
    0

    Creating a DynamicNodeList with a 'for' loop

    Using Umbraco 4.7RC

    I want to find a collection of content nodes that have certain conditions, one of them being a check to see if the page is protected. Ideally that would be possible inside a .Where() but at least in 4.7RC it isn't. You can vote for this feature at http://umbraco.codeplex.com/workitem/30096

    Until then, I will need to create my own DynamicNodeList with a 'for' loop, checking each item for various conditions. I've tried the following but they don't work.

    // get starting list of potential nodes to search
    DynamicNodeList nodesToSearch = @Model.DescendantsOrSelf().Where("umbracoNaviHide != true");
    
    // remove nodes that are protected ((this code does NOT work))
    DynamicNodeList possibleNodes = new DynamicNodeList();
    foreach (DynamicNode node in nodesToSearch) {
        if (!node.IsProtected()) {
            possibleNodes.Add(node);
        }
    }
    
    // remove nodes that are protected ((this code does NOT work))
    List<DynamicNode> possibleNodes = new List<DynamicNode>();
    foreach (DynamicNode node in nodesToSearch) {
        if (!node.IsProtected()) {
            possibleNodes.Add(node);
        }
    }
    
    

     

    How can I create my own variable that contains the nodes I want for later use?

    cheers,
    doug.

     

  • Douglas Robar 3570 posts 4711 karma points MVP ∞ admin c-trib
    Mar 02, 2011 @ 17:22
    Douglas Robar
    2

    Wait a minute... on of those DOES work! The solution is:

    // get starting list of potential nodes to search
    DynamicNodeList nodesToSearch = @Model.DescendantsOrSelf().Where("umbracoNaviHide != true");

    // remove nodes that are protected
    List<DynamicNode> possibleNodes = new List<DynamicNode>();
    foreach (DynamicNode node in nodesToSearch) {
       
    if (!node.IsProtected()) {
            possibleNodes
    .Add(node);
       
    }
    }

    Sorry for the confusion.

    cheers,
    doug.

  • Sebastiaan Janssen 5061 posts 15544 karma points MVP admin hq
    Mar 02, 2011 @ 17:23
    Sebastiaan Janssen
    0

    How does the second one not work? It works fine for me, any errors?

    Haha, too late with my reply, as usual =)

    For future reference, had to include a using statement:

    @using umbraco.MacroEngines;

  • 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.

Please Sign in or register to post replies