Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 30, 2010 @ 12:49
    Ismail Mayat
    0

    Level property from Node

    Guys,

    umbraco.presentation.nodeFactory.Node does not have level property.  Would you be able to get it doing

    umbraco.presentation.nodeFactory.Node.GetCurrent().GetProperty("level").Value

    Regards

     

    Ismail

  • Warren Buckley 2106 posts 4836 karma points MVP 8x admin c-trib
    Jul 30, 2010 @ 12:55
    Warren Buckley
    0

    Hi Ismail,
    I have just taken a quick look and I would have presumed it would have been properties of GetCurrent() such as:

    umbraco.presentation.nodeFactory.Node.GetCurrent().Path
    umbraco.presentation.nodeFactory.Node.GetCurrent().Id
    umbraco.presentation.nodeFactory.Node.GetCurrent().CreateDate

    As all of the above examples are attributes in the XML cache along with level, so it is strange that it is missing.

    Warren :)

  • Matt Brailsford 4125 posts 22224 karma points MVP 9x c-trib
    Jul 30, 2010 @ 12:57
    Matt Brailsford
    2

    Doesn't look like it.

    You could use split path on the comma, and count how many levels it is?

    umbraco.presentation.nodeFactory.Node.GetCurrent().Path.Split(',').Length

    Matt

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Jul 30, 2010 @ 13:00
    Ismail Mayat
    0

    Warren,

    Yup thats what i thought it should be there anyhow got round it i did

    var nodeAsXml = umbraco.library.GetXmlNodeById(CurrentNode.Id.ToString());
    var nodeLevel = nodeAsXml.Current.GetAttribute("level", "");

     

    Regards

    Ismail

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Jul 30, 2010 @ 13:17
    Lee Kelleher
    0

    How strange that Level is missing as a property in the Node class.

    I'd go with Matt's suggestion of splitting the Path and getting the count/length.

  • Matt Brailsford 4125 posts 22224 karma points MVP 9x c-trib
    Jul 30, 2010 @ 13:21
    Matt Brailsford
    0

    If Split isn't cool enough, you could always use a bit of Linq?

    umbraco.presentation.nodeFactory.Node.GetCurrent().Path.ToCharArray().Count(x => x == ',');

    Matt

  • Lee Kelleher 4026 posts 15837 karma points MVP 13x admin c-trib
    Jul 30, 2010 @ 13:27
    Lee Kelleher
    1

    Interesting alternatives on StackOverflow... http://stackoverflow.com/questions/541954/how-would-you-count-occurences-of-a-string-within-a-string-c

    Seems the foreach is fastest! ;-)

    string path = umbraco.presentation.nodeFactory.Node.GetCurrent().Path;
    int count = 0;
    foreach (char c in path)
      if (c == ',') count++;

    Anyway, we're talking milliseconds here... still interesting to a geek like me! ;-)

    Cheers, Lee.

  • 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