Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    May 22, 2017 @ 15:37
    Craig O'Mahony
    0

    Add to and pass List<> of nodes

    Hi Folks,

    I've got a helper method (installed as part of uBlogsy) which takes a List<> of nodes, cycles through the list and does some stuff...

    @helper renderNodes(List<umbraco.NodeFactory.Node> nodes)
    {
    
        //Does some stuff here...not included for ease of reading
    }
    

    Currently I build a list of nodes up (gained from the Alias and pass this to the helper) but I need to change my functionality.

    Basically I now have to build the list from a set number of node ID that are stored in a DB, so I'm declaring a 'node' list.

    var myNodeList = new List<umbraco.NodeFactory.Node>();
    

    And I'm trying to add to this list a node that I've gotten via it's ID but I can't see a helper in umbraco.NodeFactory.Node that allows me to do this and trying Umbraco.Content(####) allows me to get the Node but I can't add it to the list.

    Can anybody shed some light or help please?!?

    Thanks, C

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    May 22, 2017 @ 15:39
    Alex Skrypnyk
    0

    Hi Craig

    Umbraco Node and Umbraco.Content are different entities, you can't use both in one List, because List is a list of objects the same type.

    Try to use Umbraco.Content(####) for all items or event better - Umbraco.TypedContent(####)

    Thanks,

    Alex

  • Craig O'Mahony 364 posts 918 karma points
    May 22, 2017 @ 15:50
    Craig O'Mahony
    0

    Hi Alex,

    I'm not sure how to define and pass these items as a list.

    Thanks

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    May 22, 2017 @ 15:52
    Alex Skrypnyk
    0

    Craig, you can pass a list of node ids to Umbraco.TypedContent() and Umbraco.Content() and have a list of IPublishedContent what is a new way of working with Nodes in Umbraco.

    Node is deprecated, what version of Umbraco are you using?

  • Craig O'Mahony 364 posts 918 karma points
    May 22, 2017 @ 15:53
    Craig O'Mahony
    0

    I;m using 7.2.5

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    May 22, 2017 @ 15:54
    Alex Skrypnyk
    100

    You can use:

    Umbraco.TypedContent(listOfIds)
    
  • Craig Mayers 164 posts 508 karma points
    May 22, 2017 @ 15:56
    Craig Mayers
    1

    Hi Craig,

    I would recommend using the newer IPublishedContent as opposed to NodeFactory.

        var myNodeList = new List<IPublishedContent>();
        var someNode = Umbraco.TypedContent(1234);
        myNodeList.Add(someNode);
    

    Regards

    Craig

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    May 22, 2017 @ 16:02
    Alex Skrypnyk
    0

    Thanks, Craig, that's the same what I meant.

  • Craig O'Mahony 364 posts 918 karma points
    May 22, 2017 @ 16:12
    Craig O'Mahony
    0

    Got it, cheers buddy

  • Alex Skrypnyk 6182 posts 24284 karma points MVP 8x admin c-trib
    May 22, 2017 @ 16:13
    Alex Skrypnyk
    0

    Glad that you solved the issue!

    Have a nice day!

  • 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