Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 952 karma points
    Mar 21, 2013 @ 02:04
    Tom
    0

    Get Node in Umbraco 6 - new Node? Best Way?

    Hi I was just wondering the best way to get a node by ID in umbraco 6 new Node(id) doesn't work. Just wondering what people were using

     

    Also where is all the latest api documentation.. the stuff linking off the website is horribly out of date including the examples!

  • Tom 713 posts 952 karma points
    Mar 21, 2013 @ 02:14
    Tom
    0

    something like new Node(1111).ChildrenAsList.Where(c => c.NodeTypeAlias == "someAlias"); no longer works

     

    is that still best practice for querying.. the documentation above doesn't have any examples.

  • Andreas Iseli 150 posts 427 karma points
    Mar 21, 2013 @ 14:21
    Andreas Iseli
    0

    Depends on which interface you required.For just reading properties I prefer

    uQuery.GetNodeById(id)
  • Tom Fulton 2030 posts 4996 karma points c-trib
    Mar 21, 2013 @ 18:35
    Tom Fulton
    3

    I think it depends on where you're running this code.

    Inside a View or Partial, you could use:

    var content = Umbraco.TypedContent(id);

    This returns IPublishedContent, so you can do things like content.GetProperty("alias")

    You can also use the "dynamic" way:

    var content = Umbraco.Content(1234)

    Then you can do things like content.alias.  The first way is probably recommended and faster, though.  There's a little bit of info on both of these methods here:  Querying

    There's also the ContentService, which has a .GetById() method you can use.  This returns a Content object which has its own methods for property access.  At the moment I'm not exactly sure if this is meant to be used on the front-end or not, though.

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Feb 06, 2014 @ 09:31
  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Feb 06, 2014 @ 12:03
    Jeroen Breuer
    1

    Hello,

    The content service is to fetch the data from the database instead of the xml cache.

    It's better to use IPublishedContent: 

    http://our.umbraco.org/documentation/Reference/Mvc/querying

    http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

    Jeroen

  • Alex Skrypnyk 5908 posts 22603 karma points MVP 4x admin c-trib
    Feb 06, 2014 @ 13:21
    Alex Skrypnyk
    0

    Hi Jeroen )

    What about working in services and api's ?

    Thanks, Alex

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Feb 06, 2014 @ 13:24
    Jeroen Breuer
    0

    Some replies were hidden so my post might be confusing: https://twitter.com/cultiv/status/431399442227281920

    What would you like to know?

    Jeroen

  • 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